home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 6 / CU Amiga Magazine's Super CD-ROM 06 (1996)(EMAP Images)(GB)(Track 1 of 4)[!][issue 1997-01].iso / cucd / prog / gnu-c / src / gcc-2.7.0-amiga / cp / parse.y < prev    next >
Text File  |  1995-06-15  |  110KB  |  3,830 lines

  1. /* YACC parser for C++ syntax.
  2.    Copyright (C) 1988, 1989, 1993, 1995 Free Software Foundation, Inc.
  3.    Hacked by Michael Tiemann (tiemann@cygnus.com)
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 59 Temple Place - Suite 330,
  20. Boston, MA 02111-1307, USA.  */
  21.  
  22.  
  23. /* This grammar is based on the GNU CC grammar.  */
  24.  
  25. /* Note: Bison automatically applies a default action of "$$ = $1" for
  26.    all derivations; this is applied before the explicit action, if one
  27.    is given.  Keep this in mind when reading the actions.  */
  28.  
  29. %{
  30. /* Cause the `yydebug' variable to be defined.  */
  31. #define YYDEBUG 1
  32.  
  33. #include "config.h"
  34.  
  35. #include <stdio.h>
  36. #include <errno.h>
  37.  
  38. #include "tree.h"
  39. #include "input.h"
  40. #include "flags.h"
  41. #include "lex.h"
  42. #include "cp-tree.h"
  43. #include "output.h"
  44.  
  45. /* Since parsers are distinct for each language, put the language string
  46.    definition here.  (fnf) */
  47. char *language_string = "GNU C++";
  48.  
  49. extern tree void_list_node;
  50. extern struct obstack permanent_obstack;
  51.  
  52. #ifndef errno
  53. extern int errno;
  54. #endif
  55.  
  56. extern int end_of_file;
  57. extern int current_class_depth;
  58. extern int flag_new_for_scope;
  59.  
  60. void yyerror ();
  61.  
  62. /* Like YYERROR but do call yyerror.  */
  63. #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
  64.  
  65. #define OP0(NODE) (TREE_OPERAND (NODE, 0))
  66. #define OP1(NODE) (TREE_OPERAND (NODE, 1))
  67.  
  68. /* Contains the statement keyword (if/while/do) to include in an
  69.    error message if the user supplies an empty conditional expression.  */
  70. static char *cond_stmt_keyword;
  71.  
  72. /* Nonzero if we have an `extern "C"' acting as an extern specifier.  */
  73. int have_extern_spec;
  74. int used_extern_spec;
  75.  
  76. void yyhook ();
  77.  
  78. /* Cons up an empty parameter list.  */
  79. #ifdef __GNUC__
  80. __inline
  81. #endif
  82. static tree
  83. empty_parms ()
  84. {
  85.   tree parms;
  86.  
  87.   if (strict_prototype)
  88.     parms = void_list_node;
  89.   else
  90.     parms = NULL_TREE;
  91.   return parms;
  92. }
  93. %}
  94.  
  95. %start program
  96.  
  97. %union {long itype; tree ttype; char *strtype; enum tree_code code; }
  98.  
  99. /* All identifiers that are not reserved words
  100.    and are not declared typedefs in the current block */
  101. %token IDENTIFIER
  102.  
  103. /* All identifiers that are declared typedefs in the current block.
  104.    In some contexts, they are treated just like IDENTIFIER,
  105.    but they can also serve as typespecs in declarations.  */
  106. %token TYPENAME
  107.  
  108. /* Reserved words that specify storage class.
  109.    yylval contains an IDENTIFIER_NODE which indicates which one.  */
  110. %token SCSPEC
  111.  
  112. /* Reserved words that specify type.
  113.    yylval contains an IDENTIFIER_NODE which indicates which one.  */
  114. %token TYPESPEC
  115.  
  116. /* Reserved words that qualify type: "const" or "volatile".
  117.    yylval contains an IDENTIFIER_NODE which indicates which one.  */
  118. %token TYPE_QUAL
  119.  
  120. /* Character or numeric constants.
  121.    yylval is the node for the constant.  */
  122. %token CONSTANT
  123.  
  124. /* String constants in raw form.
  125.    yylval is a STRING_CST node.  */
  126. %token STRING
  127.  
  128. /* "...", used for functions with variable arglists.  */
  129. %token ELLIPSIS
  130.  
  131. /* the reserved words */
  132. /* SCO include files test "ASM", so use something else. */
  133. %token SIZEOF ENUM /* STRUCT UNION */ IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
  134. %token BREAK CONTINUE RETURN GOTO ASM_KEYWORD GCC_ASM_KEYWORD TYPEOF ALIGNOF
  135. %token HEADOF CLASSOF SIGOF
  136. %token ATTRIBUTE EXTENSION LABEL
  137.  
  138. /* the reserved words... C++ extensions */
  139. %token <ttype> AGGR
  140. %token <itype> VISSPEC
  141. %token DELETE NEW OVERLOAD THIS OPERATOR CXX_TRUE CXX_FALSE
  142. %token NAMESPACE TYPENAME_KEYWORD USING
  143. %token LEFT_RIGHT TEMPLATE
  144. %token TYPEID DYNAMIC_CAST STATIC_CAST REINTERPRET_CAST CONST_CAST
  145. %token <itype> SCOPE
  146.  
  147. /* Define the operator tokens and their precedences.
  148.    The value is an integer because, if used, it is the tree code
  149.    to use in the expression made from the operator.  */
  150.  
  151. %left EMPTY            /* used to resolve s/r with epsilon */
  152.  
  153. %left error
  154.  
  155. /* Add precedence rules to solve dangling else s/r conflict */
  156. %nonassoc IF
  157. %nonassoc ELSE
  158.  
  159. %left IDENTIFIER TYPENAME PTYPENAME SCSPEC TYPESPEC TYPE_QUAL ENUM AGGR ELLIPSIS TYPEOF SIGOF OPERATOR NSNAME TYPENAME_KEYWORD
  160.  
  161. %left '{' ',' ';'
  162.  
  163. %nonassoc THROW
  164. %right <code> ':'
  165. %right <code> ASSIGN '='
  166. %right <code> '?'
  167. %left <code> OROR
  168. %left <code> ANDAND
  169. %left <code> '|'
  170. %left <code> '^'
  171. %left <code> '&'
  172. %left <code> MIN_MAX
  173. %left <code> EQCOMPARE
  174. %left <code> ARITHCOMPARE '<' '>'
  175. %left <code> LSHIFT RSHIFT
  176. %left <code> '+' '-'
  177. %left <code> '*' '/' '%'
  178. %left <code> POINTSAT_STAR DOT_STAR
  179. %right <code> UNARY PLUSPLUS MINUSMINUS '~'
  180. %left HYPERUNARY
  181. %left <ttype> PAREN_STAR_PAREN LEFT_RIGHT
  182. %left <code> POINTSAT '.' '(' '['
  183.  
  184. %right SCOPE            /* C++ extension */
  185. %nonassoc NEW DELETE TRY CATCH
  186.  
  187. %type <code> unop
  188.  
  189. %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist
  190. %type <ttype> paren_expr_or_null nontrivial_exprlist
  191. %type <ttype> expr_no_commas cast_expr unary_expr primary string STRING
  192. %type <ttype> typed_declspecs reserved_declspecs boolean.literal
  193. %type <ttype> typed_typespecs reserved_typespecquals
  194. %type <ttype> declmods typespec typespecqual_reserved
  195. %type <ttype> SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual
  196. %type <itype> initdecls notype_initdecls initdcl    /* C++ modification */
  197. %type <ttype> init initlist maybeasm maybe_init
  198. %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
  199. %type <ttype> maybe_attribute attributes attribute attribute_list attrib
  200. %type <ttype> any_word
  201.  
  202. %type <ttype> compstmt implicitly_scoped_stmt
  203.  
  204. %type <ttype> declarator notype_declarator after_type_declarator
  205. %type <ttype> direct_notype_declarator direct_after_type_declarator
  206.  
  207. %type <ttype> structsp opt.component_decl_list component_decl_list
  208. %type <ttype> component_decl components component_declarator
  209. %type <ttype> notype_components notype_component_declarator
  210. %type <ttype> after_type_component_declarator after_type_component_declarator0
  211. %type <ttype> notype_component_declarator0 component_decl_1
  212. %type <ttype> enumlist enumerator
  213. %type <ttype> type_id absdcl type_quals
  214. %type <ttype> direct_abstract_declarator conversion_declarator
  215. %type <ttype> new_type_id new_declarator direct_new_declarator
  216. %type <ttype> xexpr parmlist parms parm bad_parm full_parm
  217. %type <ttype> identifiers_or_typenames
  218. %type <ttype> fcast_or_absdcl regcast_or_absdcl sub_cast_expr
  219. %type <ttype> expr_or_declarator complex_notype_declarator
  220. %type <ttype> notype_unqualified_id unqualified_id qualified_id
  221. %type <ttype> overqualified_id notype_qualified_id any_id
  222. %type <ttype> complex_direct_notype_declarator functional_cast
  223. %type <ttype> named_parm complex_parmlist typed_declspecs1 parms_comma
  224.  
  225. /* C++ extensions */
  226. %token <ttype> TYPENAME_ELLIPSIS PTYPENAME
  227. %token <ttype> PRE_PARSED_FUNCTION_DECL EXTERN_LANG_STRING ALL
  228. %token <ttype> PRE_PARSED_CLASS_DECL
  229. %type <ttype> fn.def1 /* Not really! */
  230. %type <ttype> fn.def2 return_id
  231. %type <ttype> named_class_head named_class_head_sans_basetype
  232. %type <ttype> unnamed_class_head
  233. %type <ttype> class_head base_class_list
  234. %type <itype> base_class_access_list
  235. %type <ttype> base_class maybe_base_class_list base_class.1
  236. %type <ttype> exception_specification_opt ansi_raise_identifier ansi_raise_identifiers
  237. %type <ttype> component_declarator0
  238. %type <ttype> operator_name
  239. %type <ttype> object aggr
  240. %type <itype> new delete
  241. /* %type <ttype> primary_no_id */
  242. %type <ttype> nonmomentary_expr maybe_parmlist
  243. %type <itype> initdcl0 notype_initdcl0 member_init_list
  244. %type <ttype> template_header template_parm_list template_parm
  245. %type <ttype> template_type_parm
  246. %type <ttype> template_type template_arg_list template_arg
  247. %type <ttype> template_instantiation template_type_name tmpl.2
  248. %type <ttype> template_instantiate_once template_instantiate_some
  249. %type <itype> fn_tmpl_end
  250. /* %type <itype> try_for_typename */
  251. %type <ttype> condition xcond paren_cond_or_null
  252. %type <ttype> type_name nested_name_specifier nested_type ptr_to_mem
  253. %type <ttype> qualified_type_name complete_type_name notype_identifier
  254. %type <ttype> complex_type_name nested_name_specifier_1
  255. %type <itype> nomods_initdecls nomods_initdcl0
  256. %type <ttype> new_initializer new_placement specialization type_specifier_seq
  257. %type <ttype> using_decl .poplevel
  258.  
  259. /* in order to recognize aggr tags as defining and thus shadowing. */
  260. %token TYPENAME_DEFN IDENTIFIER_DEFN PTYPENAME_DEFN
  261. %type <ttype> named_class_head_sans_basetype_defn 
  262. %type <ttype> identifier_defn IDENTIFIER_DEFN TYPENAME_DEFN PTYPENAME_DEFN
  263.  
  264. %token NSNAME
  265. %type <ttype> NSNAME
  266.  
  267. /* Used in lex.c for parsing pragmas.  */
  268. %token END_OF_LINE
  269.  
  270. /* lex.c and pt.c depends on this being the last token.  Define
  271.    any new tokens before this one!  */
  272. %token END_OF_SAVED_INPUT
  273.  
  274. %{
  275. /* List of types and structure classes of the current declaration.  */
  276. static tree current_declspecs;
  277. static tree prefix_attributes = NULL_TREE;
  278.  
  279. /* When defining an aggregate, this is the most recent one being defined.  */
  280. static tree current_aggr;
  281.  
  282. /* Tell yyparse how to print a token's value, if yydebug is set.  */
  283.  
  284. #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
  285. extern void yyprint ();
  286. extern tree combine_strings        PROTO((tree));
  287. %}
  288.  
  289. %%
  290. program: /* empty */
  291.     | extdefs
  292.         {
  293.           /* In case there were missing closebraces,
  294.              get us back to the global binding level.  */
  295.           while (! global_bindings_p ())
  296.             poplevel (0, 0, 0);
  297.           finish_file ();
  298.         }
  299.     ;
  300.  
  301. /* the reason for the strange actions in this rule
  302.  is so that notype_initdecls when reached via datadef
  303.  can find a valid list of type and sc specs in $0. */
  304.  
  305. extdefs:
  306.       { $<ttype>$ = NULL_TREE; } lang_extdef
  307.         { $<ttype>$ = NULL_TREE; }
  308.     | extdefs lang_extdef
  309.         { $<ttype>$ = NULL_TREE; }
  310.     ;
  311.  
  312. extdefs_opt:
  313.       extdefs
  314.     | /* empty */
  315.     ;
  316.  
  317. .hush_warning:
  318.         { have_extern_spec = 1;
  319.           used_extern_spec = 0;
  320.           $<ttype>$ = NULL_TREE; }
  321.     ;
  322. .warning_ok:
  323.         { have_extern_spec = 0; }
  324.     ;
  325.  
  326. asm_keyword:
  327.       ASM_KEYWORD
  328.     | GCC_ASM_KEYWORD
  329.     ;
  330.  
  331. lang_extdef:
  332.       { if (pending_lang_change) do_pending_lang_change(); }
  333.       extdef
  334.       { if (! toplevel_bindings_p () && ! pseudo_global_level_p())
  335.           pop_everything ();
  336.         prefix_attributes = NULL_TREE; }
  337.     ;
  338.  
  339. extdef:
  340.       fndef
  341.         { if (pending_inlines) do_pending_inlines (); }
  342.     | datadef
  343.         { if (pending_inlines) do_pending_inlines (); }
  344.     | template_def
  345.         { if (pending_inlines) do_pending_inlines (); }
  346.     | overloaddef
  347.     | asm_keyword '(' string ')' ';'
  348.         { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
  349.           assemble_asm ($3); }
  350.     | extern_lang_string '{' extdefs_opt '}'
  351.         { pop_lang_context (); }
  352.     | extern_lang_string .hush_warning fndef .warning_ok
  353.         { if (pending_inlines) do_pending_inlines ();
  354.           pop_lang_context (); }
  355.     | extern_lang_string .hush_warning datadef .warning_ok
  356.         { if (pending_inlines) do_pending_inlines ();
  357.           pop_lang_context (); }
  358.     | NAMESPACE identifier '{'
  359.         { push_namespace ($2); }
  360.       extdefs_opt '}'
  361.         { pop_namespace (); }
  362.     | NAMESPACE '{'
  363.         { push_namespace (NULL_TREE); }
  364.       extdefs_opt '}'
  365.         { pop_namespace (); }
  366.     | NAMESPACE identifier '=' any_id ';'
  367.         { do_namespace_alias ($2, $4); }
  368.     | using_decl ';'
  369.         { do_toplevel_using_decl ($1); }
  370.     | USING NAMESPACE any_id ';'
  371.         { do_using_directive ($3); }
  372.     ;
  373.  
  374. using_decl:
  375.       USING qualified_id
  376.         { $$ = $2; }
  377.     | USING global_scope qualified_id
  378.         { $$ = $3; }
  379.     | USING global_scope unqualified_id
  380.         { $$ = $3; }
  381.     ;
  382.  
  383. any_id:
  384.       unqualified_id
  385.     | qualified_id
  386.     | global_scope qualified_id
  387.         { $$ = $2; }
  388.     | global_scope unqualified_id
  389.         { $$ = $2; }
  390.     ;
  391.  
  392. extern_lang_string:
  393.     EXTERN_LANG_STRING
  394.         { push_lang_context ($1); }
  395.     | extern_lang_string EXTERN_LANG_STRING
  396.         { if (current_lang_name != $2)
  397.             cp_error ("use of linkage spec `%D' is different from previous spec `%D'", $2, current_lang_name);
  398.           pop_lang_context (); push_lang_context ($2); }
  399.     ;
  400.  
  401. template_header:
  402.       TEMPLATE '<'
  403.         { begin_template_parm_list (); }
  404.       template_parm_list '>'
  405.         { $$ = end_template_parm_list ($4); }
  406.     ;
  407.  
  408. template_parm_list:
  409.       template_parm
  410.         { $$ = process_template_parm (NULL_TREE, $1); }
  411.     | template_parm_list ',' template_parm
  412.         { $$ = process_template_parm ($1, $3); }
  413.     ;
  414.  
  415. template_type_parm:
  416.       aggr
  417.         { 
  418.           $$ = build_tree_list ($1, NULL_TREE);
  419.          ttpa:
  420.           if (TREE_PURPOSE ($$) == signature_type_node)
  421.             sorry ("signature as template type parameter");
  422.           else if (TREE_PURPOSE ($$) != class_type_node)
  423.             pedwarn ("template type parameters must use the keyword `class'");
  424.         }
  425.     | aggr identifier
  426.         { $$ = build_tree_list ($1, $2); goto ttpa; }
  427.     ;
  428.  
  429. template_parm:
  430.     /* The following rules introduce a new reduce/reduce
  431.        conflict on the ',' and '>' input tokens: they are valid
  432.        prefixes for a `structsp', which means they could match a
  433.        nameless parameter.  See 14.6, paragraph 3.
  434.        By putting them before the `parm' rule, we get
  435.        their match before considering them nameless parameter
  436.        declarations.  */
  437.       template_type_parm
  438.         { $$ = build_tree_list (NULL_TREE, $$); }
  439.     | template_type_parm '=' typespec
  440.         { $$ = build_tree_list ($3, $$); }
  441.     | full_parm
  442.     ;
  443.  
  444. overloaddef:
  445.       OVERLOAD ov_identifiers ';'
  446.         { warning ("use of `overload' is an anachronism"); }
  447.     ;
  448.  
  449. ov_identifiers: IDENTIFIER
  450.         { declare_overloaded ($1); }
  451.     | ov_identifiers ',' IDENTIFIER
  452.         { declare_overloaded ($3); }
  453.     ;
  454.       
  455. template_def:
  456.     /* Class template declarations go here; they aren't normal class
  457.        declarations, because we can't process the bodies yet.  */
  458.       template_header named_class_head_sans_basetype '{'
  459.         { yychar = '{'; goto template1; }
  460.      ';'
  461.     | template_header named_class_head_sans_basetype_defn '{'
  462.         { yychar = '{'; goto template1; }
  463.      ';'
  464.     | template_header named_class_head_sans_basetype ':'
  465.         { yychar = ':'; goto template1; }
  466.      ';'
  467.     | template_header named_class_head_sans_basetype_defn ':'
  468.         {
  469.           yychar = ':';
  470.         template1:
  471.           if (current_aggr == signature_type_node)
  472.             sorry ("template type defining a signature");
  473.           /* Maybe pedantic warning for union?
  474.              How about an enum? :-)  */
  475.           end_template_decl ($1, $2, current_aggr, 1);
  476.           reinit_parse_for_template (yychar, $1, $2);
  477.           yychar = YYEMPTY;
  478.         }
  479.       ';'
  480.     | template_header named_class_head_sans_basetype ';'
  481.         {
  482.           end_template_decl ($1, $2, current_aggr, 0);
  483.           /* declare $2 as template name with $1 parm list */
  484.         }
  485.     | template_header named_class_head_sans_basetype_defn ';'
  486.         {
  487.           end_template_decl ($1, $2, current_aggr, 0);
  488.           /* declare $2 as template name with $1 parm list */
  489.         }
  490.     | template_header /* notype_initdcl0 ';' */
  491.       notype_declarator exception_specification_opt maybeasm maybe_attribute
  492.       fn_tmpl_end
  493.         {
  494.           tree d;
  495.           int momentary;
  496.           int def = ($6 != ';');
  497.           momentary = suspend_momentary ();
  498.           d = start_decl ($<ttype>2, /*current_declspecs*/NULL_TREE, 0,
  499.                   $3);
  500.           cplus_decl_attributes (d, $5, prefix_attributes);
  501.           cp_finish_decl (d, NULL_TREE, $4, 0, 0);
  502.           end_template_decl ($1, d, 0, def);
  503.           if (def)
  504.             reinit_parse_for_template ((int) $6, $1, d);
  505.           resume_momentary (momentary);
  506.         }
  507.     | template_header typed_declspecs /*initdcl0*/
  508.       declarator exception_specification_opt maybeasm maybe_attribute
  509.       fn_tmpl_end
  510.         {
  511.           tree d;
  512.           int momentary;
  513.           int def = ($7 != ';');
  514.  
  515.           current_declspecs = $2;
  516.           momentary = suspend_momentary ();
  517.           d = start_decl ($<ttype>3, current_declspecs,
  518.                   0, $<ttype>4);
  519.           cplus_decl_attributes (d, $6, prefix_attributes);
  520.           cp_finish_decl (d, NULL_TREE, $5, 0, 0);
  521.           end_template_decl ($1, d, 0, def);
  522.           if (def)
  523.             {
  524.               reinit_parse_for_template ((int) $7, $1, d);
  525.               yychar = YYEMPTY;
  526.             }
  527.           note_list_got_semicolon ($<ttype>2);
  528.           resume_momentary (momentary);
  529.         }
  530.     | template_header declmods notype_declarator fn_tmpl_end
  531.         {
  532.           int def = ($4 != ';');
  533.           tree d = start_decl ($<ttype>3, $<ttype>2, 0, NULL_TREE);
  534.           cp_finish_decl (d, NULL_TREE, NULL_TREE, 0, 0);
  535.           end_template_decl ($1, d, 0, def);
  536.           if (def)
  537.             reinit_parse_for_template ((int) $4, $1, d);
  538.         }
  539.     /* Try to recover from syntax errors in templates.  */
  540.     | template_header error '}'    { end_template_decl ($1, 0, 0, 0); }
  541.     | template_header error ';'    { end_template_decl ($1, 0, 0, 0); }
  542.     ;
  543.  
  544. fn_tmpl_end: '{'        { $$ = '{'; }
  545.     | ':'            { $$ = ':'; }
  546.     | ';'            { $$ = ';'; }
  547.     | '='            { $$ = '='; }
  548.     | RETURN        { $$ = RETURN; }
  549.     ;
  550.  
  551. datadef:
  552.       nomods_initdecls ';'
  553.         {}
  554.     | declmods notype_initdecls ';'
  555.         {}
  556.     /* Normal case to make fast: "const i;".  */
  557.     | declmods notype_declarator ';'
  558.         { tree d;
  559.           d = start_decl ($<ttype>2, $<ttype>$, 0, NULL_TREE);
  560.           cp_finish_decl (d, NULL_TREE, NULL_TREE, 0, 0);
  561.         }
  562.     | typed_declspecs initdecls ';'
  563.         {
  564.           note_list_got_semicolon ($<ttype>$);
  565.         }
  566.     /* Normal case: make this fast.  */
  567.     | typed_declspecs declarator ';'
  568.         { tree d;
  569.           d = start_decl ($<ttype>2, $<ttype>$, 0, NULL_TREE);
  570.           cp_finish_decl (d, NULL_TREE, NULL_TREE, 0, 0);
  571.           note_list_got_semicolon ($<ttype>$);
  572.         }
  573.         | declmods ';'
  574.       { pedwarn ("empty declaration"); }
  575.     | explicit_instantiation ';'
  576.     | typed_declspecs ';'
  577.       {
  578.         tree t = $<ttype>$;
  579.         shadow_tag (t);
  580.         if (TREE_CODE (t) == TREE_LIST
  581.         && TREE_PURPOSE (t) == NULL_TREE)
  582.           {
  583.         t = TREE_VALUE (t);
  584.         if (IS_AGGR_TYPE (t)
  585.             && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (t)))
  586.           {
  587.             if (CLASSTYPE_USE_TEMPLATE (t) == 0)
  588.               SET_CLASSTYPE_TEMPLATE_SPECIALIZATION (t);
  589.             else if (CLASSTYPE_TEMPLATE_INSTANTIATION (t))
  590.               error ("override declaration for already-expanded template");
  591.           }
  592.           }
  593.         note_list_got_semicolon ($<ttype>$);
  594.       }
  595.     | error ';'
  596.     | error '}'
  597.     | ';'
  598.     ;
  599.  
  600. fndef:
  601.       fn.def1 base_init compstmt_or_error
  602.         {
  603.           finish_function (lineno, 1, 0);
  604.           /* finish_function performs these three statements:
  605.  
  606.              expand_end_bindings (getdecls (), 1, 0);
  607.              poplevel (1, 1, 0);
  608.  
  609.              expand_end_bindings (0, 0, 0);
  610.              poplevel (0, 0, 1);
  611.              */
  612.           if ($<ttype>$) process_next_inline ($<ttype>$);
  613.         }
  614.     | fn.def1 return_init base_init compstmt_or_error
  615.         {
  616.           finish_function (lineno, 1, 0);
  617.           /* finish_function performs these three statements:
  618.  
  619.              expand_end_bindings (getdecls (), 1, 0);
  620.              poplevel (1, 1, 0);
  621.  
  622.              expand_end_bindings (0, 0, 0);
  623.              poplevel (0, 0, 1);
  624.              */
  625.           if ($<ttype>$) process_next_inline ($<ttype>$);
  626.         }
  627.     | fn.def1 nodecls compstmt_or_error
  628.         { finish_function (lineno, 0, 0);
  629.           if ($<ttype>$) process_next_inline ($<ttype>$); }
  630.     | fn.def1 return_init ';' nodecls compstmt_or_error
  631.         { finish_function (lineno, 0, 0);
  632.           if ($<ttype>$) process_next_inline ($<ttype>$); }
  633.     | fn.def1 return_init nodecls compstmt_or_error
  634.         { finish_function (lineno, 0, 0);
  635.           if ($<ttype>$) process_next_inline ($<ttype>$); }
  636.     | typed_declspecs declarator error
  637.         {}
  638.     | declmods notype_declarator error
  639.         {}
  640.     | notype_declarator error
  641.         {}
  642.     ;
  643.  
  644. fn.def1:
  645.       typed_declspecs declarator exception_specification_opt
  646.         { if (! start_function ($$, $2, $3, 0))
  647.             YYERROR1;
  648.           reinit_parse_for_function ();
  649.           $$ = NULL_TREE; }
  650.     | declmods notype_declarator exception_specification_opt
  651.         { if (! start_function ($$, $2, $3, 0))
  652.             YYERROR1;
  653.           reinit_parse_for_function ();
  654.           $$ = NULL_TREE; }
  655.     | notype_declarator exception_specification_opt
  656.         { if (! start_function (NULL_TREE, $$, $2, 0))
  657.             YYERROR1;
  658.           reinit_parse_for_function ();
  659.           $$ = NULL_TREE; }
  660.     | PRE_PARSED_FUNCTION_DECL
  661.         { start_function (NULL_TREE, TREE_VALUE ($$), NULL_TREE, 1);
  662.           reinit_parse_for_function (); }
  663.     ;
  664.  
  665. /* more C++ complexity.  See component_decl for a comment on the
  666.    reduce/reduce conflict introduced by these rules.  */
  667. fn.def2:
  668.       typed_declspecs '(' parmlist ')' type_quals exception_specification_opt
  669.         {
  670.           $$ = build_parse_node (CALL_EXPR, TREE_VALUE ($1), $3, $5);
  671.           $$ = start_method (TREE_CHAIN ($1), $$, $6);
  672.          rest_of_mdef:
  673.           if (! $$)
  674.             YYERROR1;
  675.           if (yychar == YYEMPTY)
  676.             yychar = YYLEX;
  677.           reinit_parse_for_method (yychar, $$); }
  678.     | typed_declspecs LEFT_RIGHT type_quals exception_specification_opt
  679.         {
  680.           $$ = build_parse_node (CALL_EXPR, TREE_VALUE ($1),
  681.                      empty_parms (), $3);
  682.           $$ = start_method (TREE_CHAIN ($1), $$, $4);
  683.           goto rest_of_mdef;
  684.         }
  685.     | typed_declspecs declarator exception_specification_opt
  686.         { $$ = start_method ($$, $2, $3); goto rest_of_mdef; }
  687.     | declmods notype_declarator exception_specification_opt
  688.         { $$ = start_method ($$, $2, $3); goto rest_of_mdef; }
  689.     | notype_declarator exception_specification_opt
  690.         { $$ = start_method (NULL_TREE, $$, $2); goto rest_of_mdef; }
  691.     ;
  692.  
  693. return_id: RETURN IDENTIFIER
  694.         {
  695.           if (! current_function_parms_stored)
  696.             store_parm_decls ();
  697.           $$ = $2;
  698.         }
  699.     ;
  700.  
  701. return_init: return_id maybe_init
  702.         { store_return_init ($<ttype>$, $2); }
  703.     | return_id '(' nonnull_exprlist ')'
  704.         { store_return_init ($<ttype>$, $3); }
  705.     | return_id LEFT_RIGHT
  706.         { store_return_init ($<ttype>$, NULL_TREE); }
  707.     ;
  708.  
  709. base_init:
  710.       ':' .set_base_init member_init_list
  711.         {
  712.           if ($3 == 0)
  713.             error ("no base initializers given following ':'");
  714.           setup_vtbl_ptr ();
  715.           /* Always keep the BLOCK node associated with the outermost
  716.              pair of curley braces of a function.  These are needed
  717.              for correct operation of dwarfout.c.  */
  718.           keep_next_level ();
  719.         }
  720.     ;
  721.  
  722. .set_base_init:
  723.     /* empty */
  724.         {
  725.           if (! current_function_parms_stored)
  726.             store_parm_decls ();
  727.  
  728.           if (DECL_CONSTRUCTOR_P (current_function_decl))
  729.             {
  730.               /* Make a contour for the initializer list.  */
  731.               pushlevel (0);
  732.               clear_last_expr ();
  733.               expand_start_bindings (0);
  734.             }
  735.           else if (current_class_type == NULL_TREE)
  736.             error ("base initializers not allowed for non-member functions");
  737.           else if (! DECL_CONSTRUCTOR_P (current_function_decl))
  738.             error ("only constructors take base initializers");
  739.         }
  740.     ;
  741.  
  742. member_init_list:
  743.       /* empty */
  744.         { $$ = 0; }
  745.     | member_init
  746.         { $$ = 1; }
  747.     | member_init_list ',' member_init
  748.     | member_init_list error
  749.     ;
  750.  
  751. member_init: '(' nonnull_exprlist ')'
  752.         {
  753.           if (current_class_name && !flag_traditional)
  754.             pedwarn ("anachronistic old style base class initializer");
  755.           expand_member_init (C_C_D, NULL_TREE, $2);
  756.         }
  757.     | LEFT_RIGHT
  758.         {
  759.           if (current_class_name && !flag_traditional)
  760.             pedwarn ("anachronistic old style base class initializer");
  761.           expand_member_init (C_C_D, NULL_TREE, void_type_node);
  762.         }
  763.     | notype_identifier '(' nonnull_exprlist ')'
  764.         { expand_member_init (C_C_D, $<ttype>$, $3); }
  765.     | notype_identifier LEFT_RIGHT
  766.         { expand_member_init (C_C_D, $<ttype>$, void_type_node); }
  767.     | complete_type_name '(' nonnull_exprlist ')'
  768.         { expand_member_init (C_C_D, $<ttype>$, $3); }
  769.     | complete_type_name LEFT_RIGHT
  770.         { expand_member_init (C_C_D, $<ttype>$, void_type_node); }
  771.     /* GNU extension */
  772.     | notype_qualified_id '(' nonnull_exprlist ')'
  773.         {
  774.           do_member_init (OP0 ($1), OP1 ($1), $3);
  775.         }
  776.     | notype_qualified_id LEFT_RIGHT
  777.         {
  778.           do_member_init (OP0 ($1), OP1 ($1), void_type_node);
  779.         }
  780.     ;
  781.  
  782. identifier:
  783.       IDENTIFIER
  784.     | TYPENAME
  785.     | PTYPENAME
  786.     | NSNAME
  787.     ;
  788.  
  789. notype_identifier:
  790.       IDENTIFIER
  791.     | PTYPENAME 
  792.     | NSNAME %prec EMPTY
  793.     ;
  794.  
  795. identifier_defn:
  796.       IDENTIFIER_DEFN
  797.     | TYPENAME_DEFN
  798.     | PTYPENAME_DEFN
  799.     ;
  800.  
  801. explicit_instantiation:
  802.       TEMPLATE specialization template_instantiation
  803.         { do_type_instantiation ($3 ? $3 : $2, NULL_TREE); }
  804.     | TEMPLATE typed_declspecs declarator
  805.         { do_function_instantiation ($2, $3, NULL_TREE); }
  806.     | SCSPEC TEMPLATE specialization template_instantiation
  807.         { do_type_instantiation ($4 ? $4 : $3, $1); }
  808.     | SCSPEC TEMPLATE typed_declspecs declarator
  809.         { do_function_instantiation ($3, $4, $1); }
  810.     ;
  811.  
  812. template_type:
  813.       template_type_name tmpl.2 template_instantiation
  814.         { if ($3) $$ = $3; }
  815.     ;
  816.  
  817. template_type_name:
  818.       PTYPENAME '<' template_arg_list '>'
  819.         { $$ = lookup_template_class ($$, $3, NULL_TREE); }
  820.     | PTYPENAME '<' '>'
  821.         { $$ = lookup_template_class ($$, NULL_TREE, NULL_TREE); }
  822.     | TYPENAME  '<' template_arg_list '>'
  823.         { $$ = lookup_template_class ($$, $3, NULL_TREE); }
  824.     ;
  825.  
  826. tmpl.2: 
  827.       /* empty */ %prec EMPTY
  828.         { $$ = instantiate_class_template ($<ttype>0, 1); }
  829.     ;
  830.  
  831. template_arg_list:
  832.       template_arg
  833.         { $$ = build_tree_list (NULL_TREE, $$); }
  834.     | template_arg_list ',' template_arg
  835.         { $$ = chainon ($$, build_tree_list (NULL_TREE, $3)); }
  836.     ;
  837.  
  838. template_arg:
  839.       type_id
  840.         { $$ = groktypename ($$); }
  841.     | expr_no_commas  %prec UNARY
  842.     ;
  843.  
  844. template_instantiate_once:
  845.       PRE_PARSED_CLASS_DECL maybe_base_class_list
  846.         {
  847.           tree t, decl, tmpl;
  848.  
  849.           tmpl = TREE_PURPOSE (IDENTIFIER_TEMPLATE ($1));
  850.           t = xref_tag (DECL_TEMPLATE_INFO (tmpl)->aggr, $1, $2, 0);
  851.           set_current_level_tags_transparency (1);
  852.           my_friendly_assert (TREE_CODE (t) == RECORD_TYPE
  853.                       || TREE_CODE (t) == UNION_TYPE, 257);
  854.           $<ttype>$ = t;
  855.  
  856.           /* Now, put a copy of the decl in global scope, to avoid
  857.              recursive expansion.  */
  858.           decl = IDENTIFIER_LOCAL_VALUE ($1);
  859.           if (!decl)
  860.             decl = IDENTIFIER_CLASS_VALUE ($1);
  861.           /* Now, put a copy of the decl in global scope, to avoid
  862.              recursive expansion.  */
  863.                   if (decl)
  864.                     {
  865.               /* Need to copy it to clear the chain pointer,
  866.              and need to get it into permanent storage.  */
  867.                       my_friendly_assert (TREE_CODE (decl) == TYPE_DECL, 258);
  868.               push_obstacks (&permanent_obstack, &permanent_obstack);
  869.                       decl = copy_node (decl);
  870.               if (DECL_LANG_SPECIFIC (decl))
  871.             copy_lang_decl (decl);
  872.               pop_obstacks ();
  873.               pushdecl_top_level (decl);
  874.             }
  875.           /* Kludge; see instantiate_class_template.  */
  876.           TYPE_BEING_DEFINED (t) = 0;
  877.         }
  878.       left_curly opt.component_decl_list '}'
  879.         {
  880.           tree t = finish_struct ($<ttype>3, $5, 0);
  881.  
  882.           pop_obstacks ();
  883.           end_template_instantiation ($1);
  884.  
  885.           repo_template_used (t);
  886.  
  887.                   /* Now go after the methods & class data.  */
  888.                   instantiate_member_templates ($1);
  889.  
  890.           pop_tinst_level();
  891.  
  892.           CLASSTYPE_GOT_SEMICOLON (t) = 1;
  893.         }
  894.     ;
  895.  
  896. template_instantiation:
  897.           /* empty */
  898.                 { $$ = NULL_TREE; }
  899.         | template_instantiate_once
  900.                 { $$ = $1; }
  901.         ;
  902.  
  903. template_instantiate_some:
  904.           /* empty */
  905.                 { $$ = NULL_TREE; /* never used from here... */}
  906.         | template_instantiate_once template_instantiate_some
  907.                 { $$ = $1; /*???*/ }
  908.         ;
  909.  
  910. unop:     '-'
  911.         { $$ = NEGATE_EXPR; }
  912.     | '+'
  913.         { $$ = CONVERT_EXPR; }
  914.     | PLUSPLUS
  915.         { $$ = PREINCREMENT_EXPR; }
  916.     | MINUSMINUS
  917.         { $$ = PREDECREMENT_EXPR; }
  918.     | '!'
  919.         { $$ = TRUTH_NOT_EXPR; }
  920.     ;
  921.  
  922. expr:      nontrivial_exprlist
  923.         { $$ = build_x_compound_expr ($$); }
  924.     | expr_no_commas
  925.     ;
  926.  
  927. paren_expr_or_null:
  928.     LEFT_RIGHT
  929.         { error ("ANSI C++ forbids an empty condition for `%s'",
  930.              cond_stmt_keyword);
  931.           $$ = integer_zero_node; }
  932.     | '(' expr ')'
  933.         { $$ = condition_conversion ($2); }
  934.     ;
  935.  
  936. paren_cond_or_null:
  937.     LEFT_RIGHT
  938.         { error ("ANSI C++ forbids an empty condition for `%s'",
  939.              cond_stmt_keyword);
  940.           $$ = integer_zero_node; }
  941.     | '(' condition ')'
  942.         { $$ = condition_conversion ($2); }
  943.     ;
  944.  
  945. xcond:
  946.     /* empty */
  947.         { $$ = NULL_TREE; }
  948.     | condition
  949.         { $$ = condition_conversion ($$); }
  950.     | error
  951.         { $$ = NULL_TREE; }
  952.     ;
  953.  
  954. condition:
  955.     type_specifier_seq declarator exception_specification_opt maybeasm maybe_attribute '='
  956.         { {
  957.           tree d;
  958.           for (d = getdecls (); d; d = TREE_CHAIN (d))
  959.             if (TREE_CODE (d) == TYPE_DECL) {
  960.               tree s = TREE_TYPE (d);
  961.               if (TREE_CODE (s) == RECORD_TYPE)
  962.             cp_error ("definition of class `%T' in condition", s);
  963.               else if (TREE_CODE (s) == ENUMERAL_TYPE)
  964.             cp_error ("definition of enum `%T' in condition", s);
  965.             }
  966.           }
  967.           current_declspecs = $1;
  968.           $<itype>6 = suspend_momentary ();
  969.           $<ttype>$ = start_decl ($<ttype>2, current_declspecs, 1, $3);
  970.           cplus_decl_attributes ($<ttype>$, $5, prefix_attributes);
  971.         }
  972.     init
  973.         { 
  974.           cp_finish_decl ($<ttype>7, $8, $5, 0, LOOKUP_ONLYCONVERTING);
  975.           resume_momentary ($<itype>6);
  976.           $$ = $<ttype>7; 
  977.           if (TREE_CODE (TREE_TYPE ($$)) == ARRAY_TYPE)
  978.             cp_error ("definition of array `%#D' in condition", $$); 
  979.         }
  980.     | expr
  981.     ;
  982.  
  983. compstmtend:
  984.       '}'
  985.     | maybe_label_decls stmts '}'
  986.     | maybe_label_decls stmts error '}'
  987.     | maybe_label_decls error '}'
  988.     ;
  989.  
  990. already_scoped_stmt:
  991.       '{' compstmtend
  992.         { finish_stmt (); }
  993.     | simple_stmt
  994.     ;
  995.  
  996.  
  997. nontrivial_exprlist:
  998.       expr_no_commas ',' expr_no_commas
  999.         { $$ = tree_cons (NULL_TREE, $$, 
  1000.                           build_tree_list (NULL_TREE, $3)); }
  1001.     | expr_no_commas ',' error
  1002.         { $$ = tree_cons (NULL_TREE, $$, 
  1003.                           build_tree_list (NULL_TREE, error_mark_node)); }
  1004.     | nontrivial_exprlist ',' expr_no_commas
  1005.         { chainon ($$, build_tree_list (NULL_TREE, $3)); }
  1006.     | nontrivial_exprlist ',' error
  1007.         { chainon ($$, build_tree_list (NULL_TREE, error_mark_node)); }
  1008.     ;
  1009.  
  1010. nonnull_exprlist:
  1011.       expr_no_commas
  1012.         { $$ = build_tree_list (NULL_TREE, $$); }
  1013.     | nontrivial_exprlist
  1014.     ;
  1015.  
  1016. unary_expr:
  1017.       primary %prec UNARY
  1018.         {
  1019. #if 0
  1020.           if (TREE_CODE ($$) == TYPE_EXPR)
  1021.             $$ = build_component_type_expr (C_C_D, $$, NULL_TREE, 1);
  1022. #endif
  1023.         }
  1024.     /* __extension__ turns off -pedantic for following primary.  */
  1025.     | EXTENSION
  1026.         { $<itype>1 = pedantic;
  1027.           pedantic = 0; }
  1028.       cast_expr      %prec UNARY
  1029.         { $$ = $3;
  1030.           pedantic = $<itype>1; }
  1031.     | '*' cast_expr   %prec UNARY
  1032.         { $$ = build_x_indirect_ref ($2, "unary *"); }
  1033.     | '&' cast_expr   %prec UNARY
  1034.         { $$ = build_x_unary_op (ADDR_EXPR, $2); }
  1035.     | '~' cast_expr
  1036.         { $$ = build_x_unary_op (BIT_NOT_EXPR, $2); }
  1037.     | unop cast_expr  %prec UNARY
  1038.         { $$ = build_x_unary_op ($1, $2);
  1039.           if ($1 == NEGATE_EXPR && TREE_CODE ($2) == INTEGER_CST)
  1040.             TREE_NEGATED_INT ($$) = 1;
  1041.           overflow_warning ($$);
  1042.         }
  1043.     /* Refer to the address of a label as a pointer.  */
  1044.     | ANDAND identifier
  1045.         { tree label = lookup_label ($2);
  1046.           if (label == NULL_TREE)
  1047.             $$ = null_pointer_node;
  1048.           else
  1049.             {
  1050.               TREE_USED (label) = 1;
  1051.               $$ = build1 (ADDR_EXPR, ptr_type_node, label);
  1052.               TREE_CONSTANT ($$) = 1;
  1053.             }
  1054.         }
  1055.     | SIZEOF unary_expr  %prec UNARY
  1056.         { if (TREE_CODE ($2) == COMPONENT_REF
  1057.               && DECL_BIT_FIELD (TREE_OPERAND ($2, 1)))
  1058.             error ("sizeof applied to a bit-field");
  1059.           /* ANSI says arrays and functions are converted inside comma.
  1060.              But we can't really convert them in build_compound_expr
  1061.              because that would break commas in lvalues.
  1062.              So do the conversion here if operand was a comma.  */
  1063.           if (TREE_CODE ($2) == COMPOUND_EXPR
  1064.               && (TREE_CODE (TREE_TYPE ($2)) == ARRAY_TYPE
  1065.               || TREE_CODE (TREE_TYPE ($2)) == FUNCTION_TYPE))
  1066.             $2 = default_conversion ($2);
  1067.           else if (TREE_CODE ($2) == TREE_LIST)
  1068.                 {
  1069.               tree t = TREE_VALUE ($2);
  1070.               if (t != NULL_TREE
  1071.               && ((TREE_TYPE (t)
  1072.                   && TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
  1073.                   || is_overloaded_fn (t)))
  1074.             pedwarn ("ANSI C++ forbids taking the sizeof a function type");
  1075.             }
  1076.           $$ = c_sizeof (TREE_TYPE ($2)); }
  1077.     | SIZEOF '(' type_id ')'  %prec HYPERUNARY
  1078.         { $$ = c_sizeof (groktypename ($3)); }
  1079.     | ALIGNOF unary_expr  %prec UNARY
  1080.         { $$ = grok_alignof ($2); }
  1081.     | ALIGNOF '(' type_id ')'  %prec HYPERUNARY
  1082.         { $$ = c_alignof (groktypename ($3)); }
  1083.  
  1084.     /* The %prec EMPTY's here are required by the = init initializer
  1085.        syntax extension; see below.  */
  1086.     | new new_type_id %prec EMPTY
  1087.         { $$ = build_new (NULL_TREE, $2, NULL_TREE, $1); }
  1088.     | new new_type_id new_initializer
  1089.         { $$ = build_new (NULL_TREE, $2, $3, $1); }
  1090.     | new new_placement new_type_id %prec EMPTY
  1091.         { $$ = build_new ($2, $3, NULL_TREE, $1); }
  1092.     | new new_placement new_type_id new_initializer
  1093.         { $$ = build_new ($2, $3, $4, $1); }
  1094.     | new '(' type_id ')' %prec EMPTY
  1095.         { $$ = build_new (NULL_TREE, groktypename($3),
  1096.                   NULL_TREE, $1); }
  1097.     | new '(' type_id ')' new_initializer
  1098.         { $$ = build_new (NULL_TREE, groktypename($3), $5, $1); }
  1099.     | new new_placement '(' type_id ')' %prec EMPTY
  1100.         { $$ = build_new ($2, groktypename($4), NULL_TREE, $1); }
  1101.     | new new_placement '(' type_id ')' new_initializer
  1102.         { $$ = build_new ($2, groktypename($4), $6, $1); }
  1103.  
  1104.     | delete cast_expr  %prec UNARY
  1105.         { $$ = delete_sanity ($2, NULL_TREE, 0, $1); }
  1106.     | delete '[' ']' cast_expr  %prec UNARY
  1107.         { $$ = delete_sanity ($4, NULL_TREE, 1, $1);
  1108.           if (yychar == YYEMPTY)
  1109.             yychar = YYLEX; }
  1110.     | delete '[' expr ']' cast_expr %prec UNARY
  1111.         { $$ = delete_sanity ($5, $3, 2, $1);
  1112.           if (yychar == YYEMPTY)
  1113.             yychar = YYLEX; }
  1114.     ;
  1115.  
  1116. new_placement:
  1117.       '(' nonnull_exprlist ')'
  1118.         { $$ = $2; }
  1119.     | '{' nonnull_exprlist '}'
  1120.         {
  1121.           $$ = $2; 
  1122.           pedwarn ("old style placement syntax, use () instead");
  1123.         }
  1124.     ;
  1125.  
  1126. new_initializer:
  1127.       '(' nonnull_exprlist ')'
  1128.         { $$ = $2; }
  1129.     | LEFT_RIGHT
  1130.         { $$ = NULL_TREE; }
  1131.     | '(' typespec ')'
  1132.         {
  1133.           cp_error ("`%T' is not a valid expression", $2);
  1134.           $$ = error_mark_node;
  1135.         }
  1136.     /* GNU extension so people can use initializer lists.  Note that
  1137.        this alters the meaning of `new int = 1', which was previously
  1138.        syntactically valid but semantically invalid.  */
  1139.     | '=' init
  1140.         {
  1141.           if (pedantic)
  1142.             pedwarn ("ANSI C++ forbids initialization of new expression with `='");
  1143.           $$ = $2;
  1144.         }
  1145.     ;
  1146.  
  1147. /* This is necessary to postpone reduction of `int ((int)(int)(int))'.  */
  1148. regcast_or_absdcl:
  1149.       '(' type_id ')' %prec EMPTY
  1150.         { $2 = tree_cons (NULL_TREE, $2, void_list_node);
  1151.           TREE_PARMLIST ($2) = 1;
  1152.           $$ = build_parse_node (CALL_EXPR, NULL_TREE, $2, 
  1153.                      NULL_TREE); }
  1154.     | regcast_or_absdcl '(' type_id ')' %prec EMPTY
  1155.         { $3 = tree_cons (NULL_TREE, $3, void_list_node);
  1156.           TREE_PARMLIST ($3) = 1;
  1157.           $$ = build_parse_node (CALL_EXPR, $$, $3, NULL_TREE); }
  1158.     ;
  1159.  
  1160. cast_expr:
  1161.       sub_cast_expr
  1162.     | regcast_or_absdcl sub_cast_expr  %prec UNARY
  1163.         { $$ = reparse_absdcl_as_casts ($$, $2); }
  1164.     | regcast_or_absdcl '{' initlist maybecomma '}'  %prec UNARY
  1165.         { 
  1166.           tree init = build_nt (CONSTRUCTOR, NULL_TREE,
  1167.                     nreverse ($3)); 
  1168.           if (pedantic)
  1169.             pedwarn ("ANSI C++ forbids constructor-expressions");
  1170.           /* Indicate that this was a GNU C constructor expression.  */
  1171.           TREE_HAS_CONSTRUCTOR (init) = 1;
  1172.  
  1173.           $$ = reparse_absdcl_as_casts ($$, init);
  1174.         }
  1175.     ;
  1176.  
  1177. sub_cast_expr:
  1178.       unary_expr
  1179.     | HEADOF '(' expr ')'
  1180.         { $$ = build_headof ($3); }
  1181.     | CLASSOF '(' expr ')'
  1182.         { $$ = build_classof ($3); }
  1183.     | CLASSOF '(' TYPENAME ')'
  1184.         { if (is_aggr_typedef ($3, 1))
  1185.             {
  1186.               tree type = IDENTIFIER_TYPE_VALUE ($3);
  1187.               if (! IS_SIGNATURE(type))
  1188.             $$ = CLASSTYPE_RTTI (type);
  1189.               else
  1190.             {
  1191.               sorry ("signature name as argument of `classof'");
  1192.               $$ = error_mark_node;
  1193.             }
  1194.             }
  1195.           else
  1196.             $$ = error_mark_node;
  1197.         }
  1198.     ;
  1199.  
  1200. expr_no_commas:
  1201.       cast_expr
  1202.     /* Handle general members.  */
  1203.     | expr_no_commas POINTSAT_STAR expr_no_commas
  1204.         { $$ = build_x_binary_op (MEMBER_REF, $$, $3); }
  1205.     | expr_no_commas DOT_STAR expr_no_commas
  1206.         { $$ = build_m_component_ref ($$, $3); }
  1207.     | expr_no_commas '+' expr_no_commas
  1208.         { $$ = build_x_binary_op ($2, $$, $3); }
  1209.     | expr_no_commas '-' expr_no_commas
  1210.         { $$ = build_x_binary_op ($2, $$, $3); }
  1211.     | expr_no_commas '*' expr_no_commas
  1212.         { $$ = build_x_binary_op ($2, $$, $3); }
  1213.     | expr_no_commas '/' expr_no_commas
  1214.         { $$ = build_x_binary_op ($2, $$, $3); }
  1215.     | expr_no_commas '%' expr_no_commas
  1216.         { $$ = build_x_binary_op ($2, $$, $3); }
  1217.     | expr_no_commas LSHIFT expr_no_commas
  1218.         { $$ = build_x_binary_op ($2, $$, $3); }
  1219.     | expr_no_commas RSHIFT expr_no_commas
  1220.         { $$ = build_x_binary_op ($2, $$, $3); }
  1221.     | expr_no_commas ARITHCOMPARE expr_no_commas
  1222.         { $$ = build_x_binary_op ($2, $$, $3); }
  1223.     | expr_no_commas '<' expr_no_commas
  1224.         { $$ = build_x_binary_op (LT_EXPR, $$, $3); }
  1225.     | expr_no_commas '>' expr_no_commas
  1226.         { $$ = build_x_binary_op (GT_EXPR, $$, $3); }
  1227.     | expr_no_commas EQCOMPARE expr_no_commas
  1228.         { $$ = build_x_binary_op ($2, $$, $3); }
  1229.     | expr_no_commas MIN_MAX expr_no_commas
  1230.         { $$ = build_x_binary_op ($2, $$, $3); }
  1231.     | expr_no_commas '&' expr_no_commas
  1232.         { $$ = build_x_binary_op ($2, $$, $3); }
  1233.     | expr_no_commas '|' expr_no_commas
  1234.         { $$ = build_x_binary_op ($2, $$, $3); }
  1235.     | expr_no_commas '^' expr_no_commas
  1236.         { $$ = build_x_binary_op ($2, $$, $3); }
  1237.     | expr_no_commas ANDAND expr_no_commas
  1238.         { $$ = build_x_binary_op (TRUTH_ANDIF_EXPR, $$, $3); }
  1239.     | expr_no_commas OROR expr_no_commas
  1240.         { $$ = build_x_binary_op (TRUTH_ORIF_EXPR, $$, $3); }
  1241.     | expr_no_commas '?' xexpr ':' expr_no_commas
  1242.         { $$ = build_x_conditional_expr ($$, $3, $5); }
  1243.     | expr_no_commas '=' expr_no_commas
  1244.         { $$ = build_modify_expr ($$, NOP_EXPR, $3);
  1245.                   C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); }
  1246.     | expr_no_commas ASSIGN expr_no_commas
  1247.         { register tree rval;
  1248.           if ((rval = build_opfncall (MODIFY_EXPR, LOOKUP_NORMAL, $$, $3,
  1249.                          make_node ($2))))
  1250.             $$ = rval;
  1251.           else
  1252.             $$ = build_modify_expr ($$, $2, $3); }
  1253.     | THROW
  1254.         { $$ = build_throw (NULL_TREE); }
  1255.     | THROW expr_no_commas
  1256.         { $$ = build_throw ($2); }
  1257. /* These extensions are not defined.  The second arg to build_m_component_ref
  1258.    is old, build_m_component_ref now does an implicit
  1259.    build_indirect_ref (x, NULL_PTR) on the second argument.
  1260.     | object '&' expr_no_commas   %prec UNARY
  1261.         { $$ = build_m_component_ref ($$, build_x_unary_op (ADDR_EXPR, $3)); }
  1262.     | object unop expr_no_commas  %prec UNARY
  1263.         { $$ = build_m_component_ref ($$, build_x_unary_op ($2, $3)); }
  1264.     | object '(' type_id ')' expr_no_commas  %prec UNARY
  1265.         { tree type = groktypename ($3);
  1266.           $$ = build_m_component_ref ($$, build_c_cast (type, $5, 0)); }
  1267.     | object primary_no_id  %prec UNARY
  1268.         { $$ = build_m_component_ref ($$, $2); }
  1269. */
  1270.     ;
  1271.  
  1272. notype_unqualified_id:
  1273.       '~' see_typename identifier
  1274.         { $$ = build_parse_node (BIT_NOT_EXPR, $3); }
  1275.     | operator_name
  1276.     | IDENTIFIER
  1277.     | PTYPENAME
  1278.     | NSNAME %prec EMPTY
  1279.     ;
  1280.  
  1281. unqualified_id:
  1282.       notype_unqualified_id
  1283.     | TYPENAME
  1284.     ;
  1285.  
  1286. expr_or_declarator:
  1287.       notype_unqualified_id
  1288.     | '*' expr_or_declarator %prec UNARY
  1289.         { $$ = build_parse_node (INDIRECT_REF, $2); }
  1290.     | '&' expr_or_declarator %prec UNARY
  1291.         { $$ = build_parse_node (ADDR_EXPR, $2); }
  1292.     | '(' expr_or_declarator ')'
  1293.         { $$ = $2; }
  1294.     ;
  1295.  
  1296. direct_notype_declarator:
  1297.       complex_direct_notype_declarator
  1298.     | notype_unqualified_id
  1299.     | '(' expr_or_declarator ')'
  1300.         { $$ = finish_decl_parsing ($2); }
  1301.     ;
  1302.  
  1303. primary:
  1304.       notype_unqualified_id
  1305.         {
  1306.           if (TREE_CODE ($$) == BIT_NOT_EXPR)
  1307.             $$ = build_x_unary_op (BIT_NOT_EXPR, TREE_OPERAND ($$, 0));
  1308.           else if (IDENTIFIER_OPNAME_P ($$))
  1309.             {
  1310.               tree op = $$;
  1311.               $$ = lookup_name (op, 0);
  1312.               if ($$ == NULL_TREE)
  1313.             {
  1314.               if (op != ansi_opname[ERROR_MARK])
  1315.                 error ("operator %s not defined",
  1316.                    operator_name_string (op));
  1317.               $$ = error_mark_node;
  1318.             }
  1319.             }
  1320.           else
  1321.             $$ = do_identifier ($$);
  1322.         }        
  1323.     | CONSTANT
  1324.     | boolean.literal
  1325.     | string
  1326.         { $$ = combine_strings ($$); }
  1327.     | '(' expr ')'
  1328.         { char class;
  1329.           $$ = $2;
  1330.           class = TREE_CODE_CLASS (TREE_CODE ($$));
  1331.           if (class == 'e' || class == '1'
  1332.               || class == '2' || class == '<')
  1333.                     /* This inhibits warnings in truthvalue_conversion. */
  1334.             C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK); }
  1335.     | '(' expr_or_declarator ')'
  1336.         { char class;
  1337.           $$ = reparse_decl_as_expr (NULL_TREE, $2);
  1338.           class = TREE_CODE_CLASS (TREE_CODE ($$));
  1339.           if (class == 'e' || class == '1'
  1340.               || class == '2' || class == '<')
  1341.                     /* This inhibits warnings in truthvalue_conversion. */
  1342.             C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK); }
  1343.     | '(' error ')'
  1344.         { $$ = error_mark_node; }
  1345.     | '('
  1346.         { if (current_function_decl == 0)
  1347.             {
  1348.               error ("braced-group within expression allowed only inside a function");
  1349.               YYERROR;
  1350.             }
  1351.           keep_next_level ();
  1352.           $<ttype>$ = expand_start_stmt_expr (); }
  1353.       compstmt ')'
  1354.         { tree rtl_exp;
  1355.           if (pedantic)
  1356.             pedwarn ("ANSI C++ forbids braced-groups within expressions");
  1357.           rtl_exp = expand_end_stmt_expr ($<ttype>2);
  1358.           /* The statements have side effects, so the group does.  */
  1359.           TREE_SIDE_EFFECTS (rtl_exp) = 1;
  1360.  
  1361.           if (TREE_CODE ($3) == BLOCK)
  1362.             {
  1363.               /* Make a BIND_EXPR for the BLOCK already made.  */
  1364.               $$ = build (BIND_EXPR, TREE_TYPE (rtl_exp),
  1365.                   NULL_TREE, rtl_exp, $3);
  1366.               /* Remove the block from the tree at this point.
  1367.              It gets put back at the proper place
  1368.              when the BIND_EXPR is expanded.  */
  1369.               delete_block ($3);
  1370.             }
  1371.           else
  1372.             $$ = $3;
  1373.         }
  1374.     | primary '(' nonnull_exprlist ')'
  1375.                 { /* [eichin:19911016.1902EST] */
  1376.                   $<ttype>$ = build_x_function_call ($1, $3, current_class_decl); 
  1377.                   /* here we instantiate_class_template as needed... */
  1378.                   do_pending_templates ();
  1379.                 } template_instantiate_some {
  1380.                   if (TREE_CODE ($<ttype>5) == CALL_EXPR
  1381.                       && TREE_TYPE ($<ttype>5) != void_type_node)
  1382.                 $$ = require_complete_type ($<ttype>5);
  1383.                   else
  1384.                     $$ = $<ttype>5;
  1385.                 }
  1386.     | primary LEFT_RIGHT
  1387.                 {
  1388.           $$ = build_x_function_call ($$, NULL_TREE, current_class_decl);
  1389.           if (TREE_CODE ($$) == CALL_EXPR
  1390.               && TREE_TYPE ($$) != void_type_node)
  1391.             $$ = require_complete_type ($$);
  1392.                 }
  1393.     | primary '[' expr ']'
  1394.         { $$ = grok_array_decl ($$, $3); }
  1395.     | primary PLUSPLUS
  1396.         { /* If we get an OFFSET_REF, turn it into what it really
  1397.              means (e.g., a COMPONENT_REF).  This way if we've got,
  1398.              say, a reference to a static member that's being operated
  1399.              on, we don't end up trying to find a member operator for
  1400.              the class it's in.  */
  1401.           if (TREE_CODE ($$) == OFFSET_REF)
  1402.             $$ = resolve_offset_ref ($$);
  1403.           $$ = build_x_unary_op (POSTINCREMENT_EXPR, $$); }
  1404.     | primary MINUSMINUS
  1405.         { if (TREE_CODE ($$) == OFFSET_REF)
  1406.             $$ = resolve_offset_ref ($$);
  1407.           $$ = build_x_unary_op (POSTDECREMENT_EXPR, $$); }
  1408.     /* C++ extensions */
  1409.     | THIS
  1410.         { if (current_class_decl)
  1411.             {
  1412. #ifdef WARNING_ABOUT_CCD
  1413.               TREE_USED (current_class_decl) = 1;
  1414. #endif
  1415.               $$ = current_class_decl;
  1416.             }
  1417.           else if (current_function_decl
  1418.                && DECL_STATIC_FUNCTION_P (current_function_decl))
  1419.             {
  1420.               error ("`this' is unavailable for static member functions");
  1421.               $$ = error_mark_node;
  1422.             }
  1423.           else
  1424.             {
  1425.               if (current_function_decl)
  1426.             error ("invalid use of `this' in non-member function");
  1427.               else
  1428.             error ("invalid use of `this' at top level");
  1429.               $$ = error_mark_node;
  1430.             }
  1431.         }
  1432.     | TYPE_QUAL '(' nonnull_exprlist ')'
  1433.         {
  1434.           tree type;
  1435.           tree id = $$;
  1436.  
  1437.           /* This is a C cast in C++'s `functional' notation.  */
  1438.           if ($3 == error_mark_node)
  1439.             {
  1440.               $$ = error_mark_node;
  1441.               break;
  1442.             }
  1443. #if 0
  1444.           if ($3 == NULL_TREE)
  1445.             {
  1446.               error ("cannot cast null list to type `%s'",
  1447.                      IDENTIFIER_POINTER (TYPE_NAME (id)));
  1448.               $$ = error_mark_node;
  1449.               break;
  1450.             }
  1451. #endif
  1452. #if 0
  1453.           /* type is not set! (mrs) */
  1454.           if (type == error_mark_node)
  1455.             $$ = error_mark_node;
  1456.           else
  1457. #endif
  1458.             {
  1459.               if (id == ridpointers[(int) RID_CONST])
  1460.                 type = build_type_variant (integer_type_node, 1, 0);
  1461.               else if (id == ridpointers[(int) RID_VOLATILE])
  1462.                 type = build_type_variant (integer_type_node, 0, 1);
  1463. #if 0
  1464.               /* should not be able to get here (mrs) */
  1465.               else if (id == ridpointers[(int) RID_FRIEND])
  1466.                 {
  1467.                   error ("cannot cast expression to `friend' type");
  1468.                   $$ = error_mark_node;
  1469.                   break;
  1470.                 }
  1471. #endif
  1472.               else my_friendly_abort (79);
  1473.               $$ = build_c_cast (type, build_compound_expr ($3), 1);
  1474.             }
  1475.         }
  1476.     | functional_cast
  1477.     | DYNAMIC_CAST '<' type_id '>' '(' expr ')'
  1478.         { tree type = groktypename ($3);
  1479.           $$ = build_dynamic_cast (type, $6); }
  1480.     | STATIC_CAST '<' type_id '>' '(' expr ')'
  1481.         { tree type = groktypename ($3);
  1482.           $$ = build_static_cast (type, $6); }
  1483.     | REINTERPRET_CAST '<' type_id '>' '(' expr ')'
  1484.         { tree type = groktypename ($3);
  1485.           $$ = build_reinterpret_cast (type, $6); }
  1486.     | CONST_CAST '<' type_id '>' '(' expr ')'
  1487.         { tree type = groktypename ($3);
  1488.           $$ = build_const_cast (type, $6); }
  1489.     | TYPEID '(' expr ')'
  1490.         { $$ = build_typeid ($3); }
  1491.     | TYPEID '(' type_id ')'
  1492.         { tree type = groktypename ($3);
  1493.           $$ = get_typeid (TYPE_MAIN_VARIANT (type)); }
  1494.     | global_scope IDENTIFIER
  1495.         {
  1496.         do_scoped_id:
  1497.           $$ = IDENTIFIER_GLOBAL_VALUE ($2);
  1498.           if (yychar == YYEMPTY)
  1499.             yychar = YYLEX;
  1500.           if (! $$)
  1501.             {
  1502.               if (yychar == '(' || yychar == LEFT_RIGHT)
  1503.             $$ = implicitly_declare ($2);
  1504.               else
  1505.             {
  1506.               if (IDENTIFIER_GLOBAL_VALUE ($2) != error_mark_node)
  1507.                 error ("undeclared variable `%s' (first use here)",
  1508.                    IDENTIFIER_POINTER ($2));
  1509.               $$ = error_mark_node;
  1510.               /* Prevent repeated error messages.  */
  1511.               IDENTIFIER_GLOBAL_VALUE ($2) = error_mark_node;
  1512.             }
  1513.             }
  1514.           else
  1515.             {
  1516.               if (TREE_CODE ($$) == ADDR_EXPR)
  1517.             assemble_external (TREE_OPERAND ($$, 0));
  1518.               else
  1519.             assemble_external ($$);
  1520.               TREE_USED ($$) = 1;
  1521.             }
  1522.           if (TREE_CODE ($$) == CONST_DECL)
  1523.             {
  1524.               /* XXX CHS - should we set TREE_USED of the constant? */
  1525.               $$ = DECL_INITIAL ($$);
  1526.               /* This is to prevent an enum whose value is 0
  1527.              from being considered a null pointer constant.  */
  1528.               $$ = build1 (NOP_EXPR, TREE_TYPE ($$), $$);
  1529.               TREE_CONSTANT ($$) = 1;
  1530.             }
  1531.  
  1532.         }
  1533.     | global_scope operator_name
  1534.         {
  1535.           got_scope = NULL_TREE;
  1536.           if (TREE_CODE ($2) == IDENTIFIER_NODE)
  1537.             goto do_scoped_id;
  1538.           $$ = $2;
  1539.         }
  1540.     | overqualified_id %prec HYPERUNARY
  1541.         { $$ = build_offset_ref (OP0 ($$), OP1 ($$)); }
  1542.     | overqualified_id '(' nonnull_exprlist ')'
  1543.         { $$ = build_member_call (OP0 ($$), OP1 ($$), $3); }
  1544.     | overqualified_id LEFT_RIGHT
  1545.         { $$ = build_member_call (OP0 ($$), OP1 ($$), NULL_TREE); }
  1546.     | object unqualified_id  %prec UNARY
  1547.         { got_object = NULL_TREE;
  1548.           $$ = build_component_ref ($$, $2, NULL_TREE, 1); }
  1549.     | object overqualified_id %prec UNARY
  1550.         { got_object = NULL_TREE;
  1551.           $$ = build_object_ref ($$, OP0 ($2), OP1 ($2)); }
  1552.     | object unqualified_id '(' nonnull_exprlist ')'
  1553.         {
  1554.           got_object = NULL_TREE;
  1555. #if 0
  1556.           /* This is a future direction of this code, but because
  1557.              build_x_function_call cannot always undo what is done
  1558.              in build_component_ref entirely yet, we cannot do this. */
  1559.           $$ = build_x_function_call (build_component_ref ($$, $2, NULL_TREE, 1), $4, $$);
  1560.           if (TREE_CODE ($$) == CALL_EXPR
  1561.               && TREE_TYPE ($$) != void_type_node)
  1562.             $$ = require_complete_type ($$);
  1563. #else
  1564.           $$ = build_method_call ($$, $2, $4, NULL_TREE,
  1565.                       (LOOKUP_NORMAL|LOOKUP_AGGR));
  1566. #endif
  1567.         }
  1568.     | object unqualified_id LEFT_RIGHT
  1569.         {
  1570.           got_object = NULL_TREE;
  1571. #if 0
  1572.           /* This is a future direction of this code, but because
  1573.              build_x_function_call cannot always undo what is done
  1574.              in build_component_ref entirely yet, we cannot do this. */
  1575.           $$ = build_x_function_call (build_component_ref ($$, $2, NULL_TREE, 1), NULL_TREE, $$);
  1576.           if (TREE_CODE ($$) == CALL_EXPR
  1577.               && TREE_TYPE ($$) != void_type_node)
  1578.             $$ = require_complete_type ($$);
  1579. #else
  1580.           $$ = build_method_call ($$, $2, NULL_TREE, NULL_TREE,
  1581.                       (LOOKUP_NORMAL|LOOKUP_AGGR));
  1582. #endif
  1583.         }
  1584.     | object overqualified_id '(' nonnull_exprlist ')'
  1585.         {
  1586.           got_object = NULL_TREE;
  1587.           if (IS_SIGNATURE (IDENTIFIER_TYPE_VALUE (OP0 ($2))))
  1588.             {
  1589.               warning ("signature name in scope resolution ignored");
  1590.               $$ = build_method_call ($$, OP1 ($2), $4, NULL_TREE,
  1591.                           (LOOKUP_NORMAL|LOOKUP_AGGR));
  1592.             }
  1593.           else
  1594.             $$ = build_scoped_method_call ($$, OP0 ($2), OP1 ($2), $4);
  1595.         }
  1596.     | object overqualified_id LEFT_RIGHT
  1597.         {
  1598.           got_object = NULL_TREE;
  1599.           if (IS_SIGNATURE (IDENTIFIER_TYPE_VALUE (OP0 ($2))))
  1600.             {
  1601.               warning ("signature name in scope resolution ignored");
  1602.               $$ = build_method_call ($$, OP1 ($2), NULL_TREE, NULL_TREE,
  1603.                           (LOOKUP_NORMAL|LOOKUP_AGGR));
  1604.             }
  1605.           else
  1606.             $$ = build_scoped_method_call ($$, OP0 ($2), OP1 ($2), NULL_TREE);
  1607.         }
  1608.     /* p->int::~int() is valid -- 12.4 */
  1609.     | object '~' TYPESPEC LEFT_RIGHT
  1610.         {
  1611.           got_object = NULL_TREE;
  1612.           if (IDENTIFIER_GLOBAL_VALUE ($3)
  1613.               && (TREE_CODE (TREE_TYPE ($1)) 
  1614.               != TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE ($3)))))
  1615.             cp_error ("`%E' is not of type `%T'", $1, $3);
  1616.           $$ = convert (void_type_node, $1);
  1617.         }
  1618.     | object TYPESPEC SCOPE '~' TYPESPEC LEFT_RIGHT
  1619.         {
  1620.           got_object = NULL_TREE;
  1621.           if ($2 != $5)
  1622.             cp_error ("destructor specifier `%T::~%T()' must have matching names", $2, $5);
  1623.           if (TREE_CODE (TREE_TYPE ($1))
  1624.               != TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE ($2))))
  1625.             cp_error ("`%E' is not of type `%T'", $1, $2);
  1626.           $$ = convert (void_type_node, $1);
  1627.         }
  1628.     | object error
  1629.         {
  1630.           got_object = NULL_TREE;
  1631.           $$ = error_mark_node;
  1632.         }
  1633.     ;
  1634.  
  1635. /* Not needed for now.
  1636.  
  1637. primary_no_id:
  1638.       '(' expr ')'
  1639.         { $$ = $2; }
  1640.     | '(' error ')'
  1641.         { $$ = error_mark_node; }
  1642.     | '('
  1643.         { if (current_function_decl == 0)
  1644.             {
  1645.               error ("braced-group within expression allowed only inside a function");
  1646.               YYERROR;
  1647.             }
  1648.           $<ttype>$ = expand_start_stmt_expr (); }
  1649.       compstmt ')'
  1650.         { if (pedantic)
  1651.             pedwarn ("ANSI C++ forbids braced-groups within expressions");
  1652.           $$ = expand_end_stmt_expr ($<ttype>2); }
  1653.     | primary_no_id '(' nonnull_exprlist ')'
  1654.         { $$ = build_x_function_call ($$, $3, current_class_decl); }
  1655.     | primary_no_id LEFT_RIGHT
  1656.         { $$ = build_x_function_call ($$, NULL_TREE, current_class_decl); }
  1657.     | primary_no_id '[' expr ']'
  1658.         { goto do_array; }
  1659.     | primary_no_id PLUSPLUS
  1660.         { $$ = build_x_unary_op (POSTINCREMENT_EXPR, $$); }
  1661.     | primary_no_id MINUSMINUS
  1662.         { $$ = build_x_unary_op (POSTDECREMENT_EXPR, $$); }
  1663.     | SCOPE IDENTIFIER
  1664.         { goto do_scoped_id; }
  1665.     | SCOPE operator_name
  1666.         { if (TREE_CODE ($2) == IDENTIFIER_NODE)
  1667.             goto do_scoped_id;
  1668.           goto do_scoped_operator;
  1669.         }
  1670.     ;
  1671. */
  1672.  
  1673. new:      NEW
  1674.         { $$ = 0; }
  1675.     | global_scope NEW
  1676.         { got_scope = NULL_TREE; $$ = 1; }
  1677.     ;
  1678.  
  1679. delete:      DELETE
  1680.         { $$ = 0; }
  1681.     | global_scope delete
  1682.         { got_scope = NULL_TREE; $$ = 1; }
  1683.     ;
  1684.  
  1685. boolean.literal:
  1686.       CXX_TRUE
  1687.         { $$ = boolean_true_node; }
  1688.     | CXX_FALSE
  1689.         { $$ = boolean_false_node; }
  1690.     ;
  1691.  
  1692. /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it.  */
  1693. string:
  1694.       STRING
  1695.     | string STRING
  1696.         { $$ = chainon ($$, $2); }
  1697.     ;
  1698.  
  1699. nodecls:
  1700.       /* empty */
  1701.         {
  1702.           if (! current_function_parms_stored)
  1703.             store_parm_decls ();
  1704.           setup_vtbl_ptr ();
  1705.           /* Always keep the BLOCK node associated with the outermost
  1706.              pair of curley braces of a function.  These are needed
  1707.              for correct operation of dwarfout.c.  */
  1708.           keep_next_level ();
  1709.         }
  1710.     ;
  1711.  
  1712. object:      primary '.'
  1713.         { got_object = TREE_TYPE ($$); }
  1714.     | primary POINTSAT
  1715.         {
  1716.           $$ = build_x_arrow ($$); 
  1717.           got_object = TREE_TYPE ($$);
  1718.         }
  1719.     ;
  1720.  
  1721. setattrs: /* empty */
  1722.         { prefix_attributes = chainon (prefix_attributes, $<ttype>0); }
  1723.     ;
  1724.  
  1725. decl:
  1726.     /* Normal case: make this fast.  */
  1727.       typespec declarator ';'
  1728.         { tree d = get_decl_list ($1);
  1729.           int yes = suspend_momentary ();
  1730.           d = start_decl ($2, d, 0, NULL_TREE);
  1731.           cp_finish_decl (d, NULL_TREE, NULL_TREE, 0, 0);
  1732.           resume_momentary (yes);
  1733.           if (IS_AGGR_TYPE_CODE (TREE_CODE ($1)))
  1734.             note_got_semicolon ($1);
  1735.         }
  1736.     | typed_declspecs declarator ';'
  1737.         { tree d = $1;
  1738.           int yes = suspend_momentary ();
  1739.           d = start_decl ($2, d, 0, NULL_TREE);
  1740.           cp_finish_decl (d, NULL_TREE, NULL_TREE, 0, 0);
  1741.           resume_momentary (yes);
  1742.           note_list_got_semicolon ($1);
  1743.         }
  1744.     | typespec initdecls ';'
  1745.         {
  1746.           resume_momentary ($2);
  1747.           if (IS_AGGR_TYPE_CODE (TREE_CODE ($1)))
  1748.             note_got_semicolon ($1);
  1749.         }
  1750.     | typed_declspecs initdecls ';'
  1751.         {
  1752.           resume_momentary ($2);
  1753.           note_list_got_semicolon ($1);
  1754.         }
  1755.     | declmods notype_initdecls ';'
  1756.         { resume_momentary ($2); }
  1757.     | typed_declspecs ';'
  1758.         {
  1759.           shadow_tag ($1);
  1760.           note_list_got_semicolon ($1);
  1761.         }
  1762.     | declmods ';'
  1763.         { warning ("empty declaration"); }
  1764.     ;
  1765.  
  1766. /* Any kind of declarator (thus, all declarators allowed
  1767.    after an explicit typespec).  */
  1768.  
  1769. declarator:
  1770.       after_type_declarator %prec EMPTY
  1771.     | notype_declarator %prec EMPTY
  1772.     ;
  1773.  
  1774. /* This is necessary to postpone reduction of `int()()()()'.  */
  1775. fcast_or_absdcl:
  1776.       LEFT_RIGHT %prec EMPTY
  1777.         { $$ = build_parse_node (CALL_EXPR, NULL_TREE, empty_parms (),
  1778.                      NULL_TREE); }
  1779.     | fcast_or_absdcl LEFT_RIGHT %prec EMPTY
  1780.         { $$ = build_parse_node (CALL_EXPR, $$, empty_parms (), 
  1781.                      NULL_TREE); }
  1782.     ;
  1783.  
  1784. /* ANSI type-id (8.1) */
  1785. type_id:
  1786.       typed_typespecs absdcl
  1787.         { $$ = build_decl_list ($$, $2); }
  1788.     | nonempty_type_quals absdcl
  1789.         { $$ = build_decl_list ($$, $2); }
  1790.     | typespec absdcl
  1791.         { $$ = build_decl_list (get_decl_list ($$), $2); }
  1792.     | typed_typespecs %prec EMPTY
  1793.         { $$ = build_decl_list ($$, NULL_TREE); }
  1794.     | nonempty_type_quals %prec EMPTY
  1795.         { $$ = build_decl_list ($$, NULL_TREE); }
  1796.     ;
  1797.  
  1798. /* Declspecs which contain at least one type specifier or typedef name.
  1799.    (Just `const' or `volatile' is not enough.)
  1800.    A typedef'd name following these is taken as a name to be declared.  */
  1801.  
  1802. typed_declspecs:
  1803.       typed_typespecs %prec EMPTY
  1804.     | typed_declspecs1
  1805.     ;
  1806.  
  1807. typed_declspecs1:
  1808.       declmods typespec
  1809.         { $$ = decl_tree_cons (NULL_TREE, $2, $$); }
  1810.     | typespec reserved_declspecs    %prec HYPERUNARY
  1811.         { $$ = decl_tree_cons (NULL_TREE, $$, $2); }
  1812.     | typespec reserved_typespecquals reserved_declspecs
  1813.         { $$ = decl_tree_cons (NULL_TREE, $$, chainon ($2, $3)); }
  1814.     | declmods typespec reserved_declspecs
  1815.         { $$ = decl_tree_cons (NULL_TREE, $2, chainon ($3, $$)); }
  1816.     | declmods typespec reserved_typespecquals
  1817.         { $$ = decl_tree_cons (NULL_TREE, $2, chainon ($3, $$)); }
  1818.     | declmods typespec reserved_typespecquals reserved_declspecs
  1819.         { $$ = decl_tree_cons (NULL_TREE, $2, 
  1820.                        chainon ($3, chainon ($4, $$))); }
  1821.     ;
  1822.  
  1823. reserved_declspecs:
  1824.       SCSPEC
  1825.         { if (extra_warnings)
  1826.             warning ("`%s' is not at beginning of declaration",
  1827.                  IDENTIFIER_POINTER ($$));
  1828.           $$ = build_decl_list (NULL_TREE, $$); }
  1829.     | reserved_declspecs typespecqual_reserved
  1830.         { $$ = decl_tree_cons (NULL_TREE, $2, $$); }
  1831.     | reserved_declspecs SCSPEC
  1832.         { if (extra_warnings)
  1833.             warning ("`%s' is not at beginning of declaration",
  1834.                  IDENTIFIER_POINTER ($2));
  1835.           $$ = decl_tree_cons (NULL_TREE, $2, $$); }
  1836.     | reserved_declspecs attributes setattrs
  1837.         { $$ = $1; }
  1838.     | attributes setattrs
  1839.         { $$ = NULL_TREE; }
  1840.     ;
  1841.  
  1842. /* List of just storage classes and type modifiers.
  1843.    A declaration can start with just this, but then it cannot be used
  1844.    to redeclare a typedef-name.  */
  1845.  
  1846. declmods:
  1847.       nonempty_type_quals %prec EMPTY
  1848.         { TREE_STATIC ($$) = 1; }
  1849.     | SCSPEC
  1850.         { $$ = IDENTIFIER_AS_LIST ($$); }
  1851.     | declmods TYPE_QUAL
  1852.         { $$ = decl_tree_cons (NULL_TREE, $2, $$);
  1853.           TREE_STATIC ($$) = 1; }
  1854.     | declmods SCSPEC
  1855.         { if (extra_warnings && TREE_STATIC ($$))
  1856.             warning ("`%s' is not at beginning of declaration",
  1857.                  IDENTIFIER_POINTER ($2));
  1858.           $$ = decl_tree_cons (NULL_TREE, $2, $$);
  1859.           TREE_STATIC ($$) = TREE_STATIC ($1); }
  1860.     | declmods attributes setattrs
  1861.         { $$ = $1; }
  1862.     | attributes setattrs
  1863.         { $$ = NULL_TREE; }
  1864.     ;
  1865.  
  1866.  
  1867. /* Used instead of declspecs where storage classes are not allowed
  1868.    (that is, for typenames and structure components).
  1869.  
  1870.    C++ can takes storage classes for structure components.
  1871.    Don't accept a typedef-name if anything but a modifier precedes it.  */
  1872.  
  1873. typed_typespecs:
  1874.       typespec  %prec EMPTY
  1875.         { $$ = get_decl_list ($$); }
  1876.     | nonempty_type_quals typespec
  1877.         { $$ = decl_tree_cons (NULL_TREE, $2, $$); }
  1878.     | typespec reserved_typespecquals
  1879.         { $$ = decl_tree_cons (NULL_TREE, $$, $2); }
  1880.     | nonempty_type_quals typespec reserved_typespecquals
  1881.         { $$ = decl_tree_cons (NULL_TREE, $2, chainon ($3, $$)); }
  1882.     ;
  1883.  
  1884. reserved_typespecquals:
  1885.       typespecqual_reserved
  1886.         { $$ = build_decl_list (NULL_TREE, $$); }
  1887.     | reserved_typespecquals typespecqual_reserved
  1888.         { $$ = decl_tree_cons (NULL_TREE, $2, $$); }
  1889.     ;
  1890.  
  1891. /* A typespec (but not a type qualifier).
  1892.    Once we have seen one of these in a declaration,
  1893.    if a typedef name appears then it is being redeclared.  */
  1894.  
  1895. typespec: structsp
  1896.     | TYPESPEC  %prec EMPTY
  1897.     | complete_type_name
  1898.     | TYPEOF '(' expr ')'
  1899.         { $$ = TREE_TYPE ($3);
  1900.           if (pedantic)
  1901.             pedwarn ("ANSI C++ forbids `typeof'"); }
  1902.     | TYPEOF '(' type_id ')'
  1903.         { $$ = groktypename ($3);
  1904.           if (pedantic)
  1905.             pedwarn ("ANSI C++ forbids `typeof'"); }
  1906.     | SIGOF '(' expr ')'
  1907.         { tree type = TREE_TYPE ($3);
  1908.  
  1909.           if (IS_AGGR_TYPE (type))
  1910.             {
  1911.               sorry ("sigof type specifier");
  1912.               $$ = type;
  1913.             }
  1914.           else
  1915.             {
  1916.               error ("`sigof' applied to non-aggregate expression");
  1917.               $$ = error_mark_node;
  1918.             }
  1919.         }
  1920.     | SIGOF '(' type_id ')'
  1921.         { tree type = groktypename ($3);
  1922.  
  1923.           if (IS_AGGR_TYPE (type))
  1924.             {
  1925.               sorry ("sigof type specifier");
  1926.               $$ = type;
  1927.             }
  1928.           else
  1929.             {
  1930.               error("`sigof' applied to non-aggregate type");
  1931.               $$ = error_mark_node;
  1932.             }
  1933.         }
  1934.     ;
  1935.  
  1936. /* A typespec that is a reserved word, or a type qualifier.  */
  1937.  
  1938. typespecqual_reserved: TYPESPEC
  1939.     | TYPE_QUAL
  1940.     | structsp
  1941.     ;
  1942.  
  1943. initdecls:
  1944.       initdcl0
  1945.     | initdecls ',' initdcl
  1946.     ;
  1947.  
  1948. notype_initdecls:
  1949.       notype_initdcl0
  1950.     | notype_initdecls ',' initdcl
  1951.     ;
  1952.  
  1953. nomods_initdecls:
  1954.       nomods_initdcl0
  1955.     | nomods_initdecls ',' initdcl
  1956.     ;
  1957.  
  1958. maybeasm:
  1959.       /* empty */
  1960.         { $$ = NULL_TREE; }
  1961.     | asm_keyword '(' string ')'
  1962.         { if (TREE_CHAIN ($3)) $3 = combine_strings ($3); $$ = $3; }
  1963.     ;
  1964.  
  1965. initdcl0:
  1966.       declarator exception_specification_opt maybeasm maybe_attribute '='
  1967.         { current_declspecs = $<ttype>0;
  1968.           if (TREE_CODE (current_declspecs) != TREE_LIST)
  1969.             current_declspecs = get_decl_list (current_declspecs);
  1970.           if (have_extern_spec && !used_extern_spec)
  1971.             {
  1972.               current_declspecs = decl_tree_cons
  1973.             (NULL_TREE, get_identifier ("extern"), 
  1974.              current_declspecs);
  1975.               used_extern_spec = 1;
  1976.             }
  1977.           $<itype>5 = suspend_momentary ();
  1978.           $<ttype>$ = start_decl ($<ttype>1, current_declspecs, 1, $2);
  1979.           cplus_decl_attributes ($<ttype>$, $4, prefix_attributes); }
  1980.       init
  1981. /* Note how the declaration of the variable is in effect while its init is parsed! */
  1982.         { cp_finish_decl ($<ttype>6, $7, $3, 0, LOOKUP_ONLYCONVERTING);
  1983.           $$ = $<itype>5; }
  1984.     | declarator exception_specification_opt maybeasm maybe_attribute
  1985.         { tree d;
  1986.           current_declspecs = $<ttype>0;
  1987.           if (TREE_CODE (current_declspecs) != TREE_LIST)
  1988.             current_declspecs = get_decl_list (current_declspecs);
  1989.           if (have_extern_spec && !used_extern_spec)
  1990.             {
  1991.               current_declspecs = decl_tree_cons
  1992.             (NULL_TREE, get_identifier ("extern"), 
  1993.              current_declspecs);
  1994.               used_extern_spec = 1;
  1995.             }
  1996.           $$ = suspend_momentary ();
  1997.           d = start_decl ($<ttype>1, current_declspecs, 0, $2);
  1998.           cplus_decl_attributes (d, $4, prefix_attributes);
  1999.           cp_finish_decl (d, NULL_TREE, $3, 0, 0); }
  2000.     ;
  2001.  
  2002. initdcl:
  2003.       declarator exception_specification_opt maybeasm maybe_attribute '='
  2004.         { $<ttype>$ = start_decl ($<ttype>1, current_declspecs, 1, $2);
  2005.           cplus_decl_attributes ($<ttype>$, $4, prefix_attributes); }
  2006.       init
  2007. /* Note how the declaration of the variable is in effect while its init is parsed! */
  2008.         { cp_finish_decl ($<ttype>6, $7, $3, 0, LOOKUP_ONLYCONVERTING); }
  2009.     | declarator exception_specification_opt maybeasm maybe_attribute
  2010.         { $<ttype>$ = start_decl ($<ttype>1, current_declspecs, 0, $2);
  2011.           cplus_decl_attributes ($<ttype>$, $4, prefix_attributes);
  2012.           cp_finish_decl ($<ttype>$, NULL_TREE, $3, 0, 0); }
  2013.     ;
  2014.  
  2015. notype_initdcl0:
  2016.       notype_declarator exception_specification_opt maybeasm maybe_attribute '='
  2017.         { current_declspecs = $<ttype>0;
  2018.           $<itype>5 = suspend_momentary ();
  2019.           $<ttype>$ = start_decl ($<ttype>1, current_declspecs, 1, $2);
  2020.           cplus_decl_attributes ($<ttype>$, $4, prefix_attributes); }
  2021.       init
  2022. /* Note how the declaration of the variable is in effect while its init is parsed! */
  2023.         { cp_finish_decl ($<ttype>6, $7, $3, 0, LOOKUP_ONLYCONVERTING);
  2024.           $$ = $<itype>5; }
  2025.     | notype_declarator exception_specification_opt maybeasm maybe_attribute
  2026.         { tree d;
  2027.           current_declspecs = $<ttype>0;
  2028.           $$ = suspend_momentary ();
  2029.           d = start_decl ($<ttype>1, current_declspecs, 0, $2);
  2030.           cplus_decl_attributes (d, $4, prefix_attributes);
  2031.           cp_finish_decl (d, NULL_TREE, $3, 0, 0); }
  2032.     ;
  2033.  
  2034. nomods_initdcl0:
  2035.       notype_declarator exception_specification_opt maybeasm maybe_attribute '='
  2036.         { current_declspecs = NULL_TREE;
  2037.           $<itype>5 = suspend_momentary ();
  2038.           $<ttype>$ = start_decl ($1, current_declspecs, 1, $2);
  2039.           cplus_decl_attributes ($<ttype>$, $4, prefix_attributes); }
  2040.       init
  2041. /* Note how the declaration of the variable is in effect while its init is parsed! */
  2042.         { cp_finish_decl ($<ttype>6, $7, $3, 0, LOOKUP_ONLYCONVERTING);
  2043.           $$ = $<itype>5; }
  2044.     | notype_declarator exception_specification_opt maybeasm maybe_attribute
  2045.         { tree d;
  2046.           current_declspecs = NULL_TREE;
  2047.           $$ = suspend_momentary ();
  2048.           d = start_decl ($1, current_declspecs, 0, $2);
  2049.           cplus_decl_attributes (d, $4, prefix_attributes);
  2050.           cp_finish_decl (d, NULL_TREE, $3, 0, 0); }
  2051.     ;
  2052.  
  2053. /* the * rules are dummies to accept the Apollo extended syntax
  2054.    so that the header files compile. */
  2055. maybe_attribute:
  2056.       /* empty */
  2057.           { $$ = NULL_TREE; }
  2058.     | attributes
  2059.         { $$ = $1; }
  2060.     ;
  2061.  
  2062. attributes:
  2063.       attribute
  2064.         { $$ = $1; }
  2065.     | attributes attribute
  2066.         { $$ = chainon ($1, $2); }
  2067.     ;
  2068.  
  2069. attribute:
  2070.       ATTRIBUTE '(' '(' attribute_list ')' ')'
  2071.         { $$ = $4; }
  2072.     ;
  2073.  
  2074. attribute_list:
  2075.       attrib
  2076.         { $$ = $1; }
  2077.     | attribute_list ',' attrib
  2078.         { $$ = chainon ($1, $3); }
  2079.     ;
  2080.  
  2081. attrib:
  2082.     /* empty */
  2083.         { $$ = NULL_TREE; }
  2084.     | any_word
  2085.         { $$ = build_tree_list ($1, NULL_TREE); }
  2086.     | any_word '(' IDENTIFIER ')'
  2087.         { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
  2088.     | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
  2089.         { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
  2090.     | any_word '(' nonnull_exprlist ')'
  2091.         { $$ = build_tree_list ($1, $3); }
  2092.     ;
  2093.  
  2094. /* This still leaves out most reserved keywords,
  2095.    shouldn't we include them?  */
  2096.  
  2097. any_word:
  2098.       identifier
  2099.     | SCSPEC
  2100.     | TYPESPEC
  2101.     | TYPE_QUAL
  2102.     ;
  2103.  
  2104. /* A nonempty list of identifiers, including typenames.  */
  2105. identifiers_or_typenames:
  2106.     identifier
  2107.         { $$ = build_tree_list (NULL_TREE, $1); }
  2108.     | identifiers_or_typenames ',' identifier
  2109.         { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
  2110.     ;
  2111.  
  2112. maybe_init:
  2113.     %prec EMPTY /* empty */
  2114.         { $$ = NULL_TREE; }
  2115.     | '=' init
  2116.         { $$ = $2; }
  2117.  
  2118. init:
  2119.       expr_no_commas %prec '='
  2120.     | '{' '}'
  2121.         { $$ = build_nt (CONSTRUCTOR, NULL_TREE, NULL_TREE);
  2122.           TREE_HAS_CONSTRUCTOR ($$) = 1; }
  2123.     | '{' initlist '}'
  2124.         { $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2));
  2125.           TREE_HAS_CONSTRUCTOR ($$) = 1; }
  2126.     | '{' initlist ',' '}'
  2127.         { $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2));
  2128.           TREE_HAS_CONSTRUCTOR ($$) = 1; }
  2129.     | error
  2130.         { $$ = NULL_TREE; }
  2131.     ;
  2132.  
  2133. /* This chain is built in reverse order,
  2134.    and put in forward order where initlist is used.  */
  2135. initlist:
  2136.       init
  2137.         { $$ = build_tree_list (NULL_TREE, $$); }
  2138.     | initlist ',' init
  2139.         { $$ = tree_cons (NULL_TREE, $3, $$); }
  2140.     /* These are for labeled elements.  */
  2141.     | '[' expr_no_commas ']' init
  2142.         { $$ = build_tree_list ($2, $4); }
  2143.     | initlist ',' CASE expr_no_commas ':' init
  2144.         { $$ = tree_cons ($4, $6, $$); }
  2145.     | identifier ':' init
  2146.         { $$ = build_tree_list ($$, $3); }
  2147.     | initlist ',' identifier ':' init
  2148.         { $$ = tree_cons ($3, $5, $$); }
  2149.     ;
  2150.  
  2151. structsp:
  2152.       ENUM identifier '{'
  2153.         { $<itype>3 = suspend_momentary ();
  2154.           $$ = start_enum ($2); }
  2155.       enumlist maybecomma_warn '}'
  2156.         { $$ = finish_enum ($<ttype>4, $5);
  2157.           resume_momentary ((int) $<itype>3);
  2158.           check_for_missing_semicolon ($<ttype>4); }
  2159.     | ENUM identifier '{' '}'
  2160.         { $$ = finish_enum (start_enum ($2), NULL_TREE);
  2161.           check_for_missing_semicolon ($$); }
  2162.     | ENUM '{'
  2163.         { $<itype>2 = suspend_momentary ();
  2164.           $$ = start_enum (make_anon_name ()); }
  2165.       enumlist maybecomma_warn '}'
  2166.         { $$ = finish_enum ($<ttype>3, $4);
  2167.           resume_momentary ((int) $<itype>1);
  2168.           check_for_missing_semicolon ($<ttype>3); }
  2169.     | ENUM '{' '}'
  2170.         { $$ = finish_enum (start_enum (make_anon_name()), NULL_TREE);
  2171.           check_for_missing_semicolon ($$); }
  2172.     | ENUM identifier
  2173.         { $$ = xref_tag (enum_type_node, $2, NULL_TREE, 1); }
  2174.     | ENUM complex_type_name
  2175.         { $$ = xref_tag (enum_type_node, $2, NULL_TREE, 1); }
  2176.     | TYPENAME_KEYWORD complex_type_name
  2177.         { $$ = $2; }
  2178.     /* C++ extensions, merged with C to avoid shift/reduce conflicts */
  2179.     | class_head left_curly opt.component_decl_list '}'
  2180.         {
  2181.           int semi;
  2182.           tree id;
  2183.  
  2184. #if 0
  2185.           /* Need to rework class nesting in the
  2186.              presence of nested classes, etc.  */
  2187.           shadow_tag (CLASSTYPE_AS_LIST ($$)); */
  2188. #endif
  2189.           if (yychar == YYEMPTY)
  2190.             yychar = YYLEX;
  2191.           semi = yychar == ';';
  2192.           /* finish_struct nukes this anyway; if
  2193.              finish_exception does too, then it can go. */
  2194.           if (semi)
  2195.             note_got_semicolon ($$);
  2196.  
  2197.           if (TREE_CODE ($$) == ENUMERAL_TYPE)
  2198.             /* $$ = $1 from default rule.  */;
  2199.           else
  2200.             {
  2201.               $$ = finish_struct ($$, $3, semi);
  2202.               if (semi) note_got_semicolon ($$);
  2203.             }
  2204.  
  2205.           pop_obstacks ();
  2206.  
  2207.           id = TYPE_IDENTIFIER ($$);
  2208.           if (id && IDENTIFIER_TEMPLATE (id))
  2209.             {
  2210.               tree decl;
  2211.  
  2212.               /* I don't know if the copying of this TYPE_DECL is
  2213.                * really needed.  However, it's such a small per-
  2214.                * formance penalty that the extra safety is a bargain.
  2215.                * - niklas@appli.se
  2216.                */
  2217.               push_obstacks (&permanent_obstack, &permanent_obstack);
  2218.               decl = copy_node (lookup_name (id, 0));
  2219.               if (DECL_LANG_SPECIFIC (decl))
  2220.             copy_lang_decl (decl);
  2221.               pop_obstacks ();
  2222.               undo_template_name_overload (id, 0);
  2223.               pushdecl_top_level (decl);
  2224.             }
  2225.           if (! semi)
  2226.             check_for_missing_semicolon ($$); }
  2227.     | class_head  %prec EMPTY
  2228.         {
  2229.           /* struct B: public A; is not accepted by the WP grammar.  */
  2230.           if (TYPE_BINFO_BASETYPES ($$) && !TYPE_SIZE ($$)
  2231.               && ! TYPE_BEING_DEFINED ($$))
  2232.             cp_error ("base clause without member specification for `%#T'",
  2233.                   $$);
  2234.         }
  2235.     ;
  2236.  
  2237. maybecomma:
  2238.       /* empty */
  2239.     | ','
  2240.     ;
  2241.  
  2242. maybecomma_warn:
  2243.       /* empty */
  2244.     | ','
  2245.         { if (pedantic) pedwarn ("comma at end of enumerator list"); }
  2246.     ;
  2247.  
  2248. aggr:      AGGR
  2249.     | aggr SCSPEC
  2250.         { error ("storage class specifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); }
  2251.     | aggr TYPESPEC
  2252.         { error ("type specifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); }
  2253.     | aggr TYPE_QUAL
  2254.         { error ("type qualifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); }
  2255.     | aggr AGGR
  2256.         { error ("no body nor ';' separates two class, struct or union declarations"); }
  2257.     ;
  2258.  
  2259. specialization:
  2260.       aggr template_type_name ';'
  2261.         { 
  2262.           yyungetc (';', 1); current_aggr = $$; $$ = $2; 
  2263.           if ($<ttype>0 == ridpointers[(int) RID_TEMPLATE])
  2264.             instantiate_class_template ($$, 2);
  2265.         }
  2266.     ;
  2267.  
  2268. named_class_head_sans_basetype:
  2269.       aggr identifier
  2270.         { current_aggr = $$; $$ = $2; }
  2271.     | aggr complex_type_name
  2272.         { current_aggr = $$; $$ = $2; }
  2273.     | aggr template_type %prec EMPTY
  2274.         { current_aggr = $$; $$ = $2; }
  2275.     | specialization
  2276.     ;
  2277.  
  2278. named_class_head_sans_basetype_defn:
  2279.       aggr identifier_defn %prec EMPTY
  2280.         { current_aggr = $$; $$ = $2; }
  2281.     | aggr template_type_name '{'
  2282.         { yyungetc ('{', 1);
  2283.         aggr2:
  2284.           current_aggr = $$;
  2285.           $$ = $2;
  2286.           overload_template_name ($$, 0); }
  2287.     | aggr template_type_name ':'
  2288.         { yyungetc (':', 1); goto aggr2; }
  2289.     ;
  2290.  
  2291. do_xref_defn: /* empty */ %prec EMPTY
  2292.         { $<ttype>$ = xref_tag (current_aggr, $<ttype>0, NULL_TREE, 0); }
  2293.     ;
  2294.  
  2295. named_class_head:
  2296.       named_class_head_sans_basetype %prec EMPTY
  2297.         { $$ = xref_tag (current_aggr, $1, NULL_TREE, 1); }
  2298.     | named_class_head_sans_basetype_defn do_xref_defn
  2299.           maybe_base_class_list %prec EMPTY
  2300.         { 
  2301.           $$ = $<ttype>2;
  2302.           if ($3)
  2303.                     xref_basetypes (current_aggr, $1, $<ttype>2, $3); 
  2304.         }
  2305.     ;
  2306.  
  2307. unnamed_class_head: aggr '{'
  2308.         { $$ = xref_tag ($$, make_anon_name (), NULL_TREE, 0);
  2309.           yyungetc ('{', 1); }
  2310.     ;
  2311.  
  2312. class_head: unnamed_class_head | named_class_head ;
  2313.  
  2314. maybe_base_class_list:
  2315.       %prec EMPTY /* empty */
  2316.         { $$ = NULL_TREE; }
  2317.     | ':'  %prec EMPTY
  2318.         { yyungetc(':', 1); $$ = NULL_TREE; }
  2319.     | ':' base_class_list  %prec EMPTY
  2320.         { $$ = $2; }
  2321.     ;
  2322.  
  2323. base_class_list:
  2324.       base_class
  2325.     | base_class_list ',' base_class
  2326.         { $$ = chainon ($$, $3); }
  2327.     ;
  2328.  
  2329. base_class:
  2330.       base_class.1
  2331.         {
  2332.           tree type;
  2333.          do_base_class1:
  2334.           type = IDENTIFIER_TYPE_VALUE ($$);
  2335.           if (! is_aggr_typedef ($$, 1))
  2336.             $$ = NULL_TREE;
  2337.           else if (current_aggr == signature_type_node
  2338.                && (! type) && (! IS_SIGNATURE (type)))
  2339.             {
  2340.               error ("class name not allowed as base signature");
  2341.               $$ = NULL_TREE;
  2342.             }
  2343.           else if (current_aggr == signature_type_node)
  2344.             {
  2345.               sorry ("signature inheritance, base type `%s' ignored",
  2346.                  IDENTIFIER_POINTER ($$));
  2347.               $$ = build_tree_list ((tree)access_public, $$);
  2348.             }
  2349.           else if (type && IS_SIGNATURE (type))
  2350.             {
  2351.               error ("signature name not allowed as base class");
  2352.               $$ = NULL_TREE;
  2353.             }
  2354.           else
  2355.             $$ = build_tree_list ((tree)access_default, $$);
  2356.         }
  2357.     | base_class_access_list base_class.1
  2358.         {
  2359.           tree type;
  2360.          do_base_class2:
  2361.           type = IDENTIFIER_TYPE_VALUE ($2);
  2362.           if (current_aggr == signature_type_node)
  2363.             error ("access and source specifiers not allowed in signature");
  2364.           if (! is_aggr_typedef ($2, 1))
  2365.             $$ = NULL_TREE;
  2366.           else if (current_aggr == signature_type_node
  2367.                && (! type) && (! IS_SIGNATURE (type)))
  2368.             {
  2369.               error ("class name not allowed as base signature");
  2370.               $$ = NULL_TREE;
  2371.             }
  2372.           else if (current_aggr == signature_type_node)
  2373.             {
  2374.               sorry ("signature inheritance, base type `%s' ignored",
  2375.                  IDENTIFIER_POINTER ($$));
  2376.               $$ = build_tree_list ((tree)access_public, $2);
  2377.             }
  2378.           else if (type && IS_SIGNATURE (type))
  2379.             {
  2380.               error ("signature name not allowed as base class");
  2381.               $$ = NULL_TREE;
  2382.             }
  2383.           else
  2384.             $$ = build_tree_list ((tree) $$, $2);
  2385.         }
  2386.     ;
  2387.  
  2388. base_class.1:
  2389.       complete_type_name
  2390.     | SIGOF '(' expr ')'
  2391.         {
  2392.           if (current_aggr == signature_type_node)
  2393.             {
  2394.               if (IS_AGGR_TYPE (TREE_TYPE ($3)))
  2395.             {
  2396.               sorry ("`sigof' as base signature specifier");
  2397.               /* need to return some dummy signature identifier */
  2398.               $$ = $3;
  2399.             }
  2400.               else
  2401.             {
  2402.               error ("`sigof' applied to non-aggregate expression");
  2403.               $$ = error_mark_node;
  2404.             }
  2405.             }
  2406.           else
  2407.             {
  2408.               error ("`sigof' in struct or class declaration");
  2409.               $$ = error_mark_node;
  2410.             }
  2411.         }
  2412.     | SIGOF '(' type_id ')'
  2413.         {
  2414.           if (current_aggr == signature_type_node)
  2415.             {
  2416.               if (IS_AGGR_TYPE (groktypename ($3)))
  2417.             {
  2418.               sorry ("`sigof' as base signature specifier");
  2419.               /* need to return some dummy signature identifier */
  2420.               $$ = $3;
  2421.             }
  2422.               else
  2423.             {
  2424.               error ("`sigof' applied to non-aggregate expression");
  2425.               $$ = error_mark_node;
  2426.             }
  2427.             }
  2428.           else
  2429.             {
  2430.               error ("`sigof' in struct or class declaration");
  2431.               $$ = error_mark_node;
  2432.             }
  2433.         }
  2434.     ;
  2435.  
  2436. base_class_access_list:
  2437.       VISSPEC
  2438.     | SCSPEC
  2439.         { if ($<ttype>$ != ridpointers[(int)RID_VIRTUAL])
  2440.             sorry ("non-virtual access");
  2441.           $$ = access_default_virtual; }
  2442.     | base_class_access_list VISSPEC
  2443.         { int err = 0;
  2444.           if ($2 == access_protected)
  2445.             {
  2446.               warning ("`protected' access not implemented");
  2447.               $2 = access_public;
  2448.               err++;
  2449.             }
  2450.           else if ($2 == access_public)
  2451.             {
  2452.               if ($1 == access_private)
  2453.             {
  2454.             mixed:
  2455.               error ("base class cannot be public and private");
  2456.             }
  2457.               else if ($1 == access_default_virtual)
  2458.             $$ = access_public_virtual;
  2459.             }
  2460.           else /* $2 == access_private */
  2461.             {
  2462.               if ($1 == access_public)
  2463.             goto mixed;
  2464.               else if ($1 == access_default_virtual)
  2465.             $$ = access_private_virtual;
  2466.             }
  2467.         }
  2468.     | base_class_access_list SCSPEC
  2469.         { if ($2 != ridpointers[(int)RID_VIRTUAL])
  2470.             sorry ("non-virtual access");
  2471.           if ($$ == access_public)
  2472.             $$ = access_public_virtual;
  2473.           else if ($$ == access_private)
  2474.             $$ = access_private_virtual; }
  2475.     ;
  2476.  
  2477. left_curly: '{'
  2478.         { tree t = $<ttype>0;
  2479.           push_obstacks_nochange ();
  2480.           end_temporary_allocation ();
  2481.  
  2482.           if (! IS_AGGR_TYPE (t))
  2483.             {
  2484.               t = $<ttype>0 = make_lang_type (RECORD_TYPE);
  2485.               TYPE_NAME (t) = get_identifier ("erroneous type");
  2486.             }
  2487.           if (TYPE_SIZE (t))
  2488.             duplicate_tag_error (t);
  2489.                   if (TYPE_SIZE (t) || TYPE_BEING_DEFINED (t))
  2490.                     {
  2491.                       t = make_lang_type (TREE_CODE (t));
  2492.                       pushtag (TYPE_IDENTIFIER ($<ttype>0), t, 0);
  2493.                       $<ttype>0 = t;
  2494.                     }
  2495.           pushclass (t, 0);
  2496.           TYPE_BEING_DEFINED (t) = 1;
  2497.           /* Reset the interface data, at the earliest possible
  2498.              moment, as it might have been set via a class foo;
  2499.              before.  */
  2500.           /* Don't change signatures.  */
  2501.           if (! IS_SIGNATURE (t))
  2502.             {
  2503.               extern tree pending_vtables;
  2504.               int needs_writing;
  2505.               tree name = TYPE_IDENTIFIER (t);
  2506.  
  2507.               if (! ANON_AGGRNAME_P (name))
  2508.             {
  2509.               CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
  2510.               SET_CLASSTYPE_INTERFACE_UNKNOWN_X
  2511.                 (t, interface_unknown);
  2512.             }
  2513.  
  2514.               /* Record how to set the access of this class's
  2515.              virtual functions.  If write_virtuals == 2 or 3, then
  2516.              inline virtuals are ``extern inline''.  */
  2517.               switch (write_virtuals)
  2518.             {
  2519.             case 0:
  2520.             case 1:
  2521.               needs_writing = 1;
  2522.               break;
  2523.             case 2:
  2524.               needs_writing = !! value_member (name, pending_vtables);
  2525.               break;
  2526.             case 3:
  2527.               needs_writing = ! CLASSTYPE_INTERFACE_ONLY (t)
  2528.                 && CLASSTYPE_INTERFACE_KNOWN (t);
  2529.               break;
  2530.             default:
  2531.               needs_writing = 0;
  2532.             }
  2533.               CLASSTYPE_VTABLE_NEEDS_WRITING (t) = needs_writing;
  2534.             }
  2535. #if 0
  2536.           t = TYPE_IDENTIFIER ($<ttype>0);
  2537.           if (t && IDENTIFIER_TEMPLATE (t))
  2538.             overload_template_name (t, 1);
  2539. #endif
  2540.         }
  2541.     ;
  2542.  
  2543. opt.component_decl_list:
  2544.     /* empty */
  2545.         { $$ = NULL_TREE; }
  2546.     | component_decl_list
  2547.         {
  2548.           if (current_aggr == signature_type_node)
  2549.             $$ = build_tree_list ((tree) access_public, $$);
  2550.           else
  2551.             $$ = build_tree_list ((tree) access_default, $$);
  2552.         }
  2553.     | opt.component_decl_list VISSPEC ':' component_decl_list
  2554.         {
  2555.           tree visspec = (tree) $2;
  2556.  
  2557.           if (current_aggr == signature_type_node)
  2558.             {
  2559.               error ("access specifier not allowed in signature");
  2560.               visspec = (tree) access_public;
  2561.             }
  2562.           $$ = chainon ($$, build_tree_list (visspec, $4));
  2563.         }
  2564.     | opt.component_decl_list VISSPEC ':'
  2565.         {
  2566.           if (current_aggr == signature_type_node)
  2567.             error ("access specifier not allowed in signature");
  2568.         }
  2569.     ;
  2570.  
  2571. /* Note: we no longer warn about the semicolon after a component_decl_list.
  2572.    ARM $9.2 says that the semicolon is optional, and therefore allowed.  */
  2573. component_decl_list:
  2574.       component_decl
  2575.         { if ($$ == void_type_node) $$ = NULL_TREE; 
  2576.         }
  2577.     | component_decl_list component_decl
  2578.         { /* In pushdecl, we created a reverse list of names
  2579.              in this binding level.  Make sure that the chain
  2580.              of what we're trying to add isn't the item itself
  2581.              (which can happen with what pushdecl's doing).  */
  2582.           if ($2 != NULL_TREE && $2 != void_type_node)
  2583.             {
  2584.               if (TREE_CHAIN ($2) != $$)
  2585.             $$ = chainon ($$, $2);
  2586.               else
  2587.             $$ = $2;
  2588.             }
  2589.         }
  2590.     ;
  2591.  
  2592. component_decl:
  2593.       component_decl_1 ';'
  2594.     | component_decl_1 '}'
  2595.         { error ("missing ';' before right brace");
  2596.           yyungetc ('}', 0); }
  2597.     /* C++: handle constructors, destructors and inline functions */
  2598.     /* note that INLINE is like a TYPESPEC */
  2599.     | fn.def2 ':' /* base_init compstmt */
  2600.         { $$ = finish_method ($$); }
  2601.     | fn.def2 '{' /* nodecls compstmt */
  2602.         { $$ = finish_method ($$); }
  2603.     | ';'
  2604.         { $$ = NULL_TREE; }
  2605.     ;
  2606.  
  2607. component_decl_1:
  2608.     /* Do not add a "typed_declspecs declarator" rule here for
  2609.        speed; we need to call grok_x_components for enums, so the
  2610.        speedup would be insignificant.  */
  2611.       typed_declspecs components
  2612.         {
  2613.           $$ = grok_x_components ($$, $2);
  2614.         }
  2615.     | declmods notype_components
  2616.         { 
  2617.           $$ = grok_x_components ($$, $2);
  2618.         }
  2619.     | notype_declarator exception_specification_opt maybeasm maybe_attribute maybe_init
  2620.         { $$ = grokfield ($$, NULL_TREE, $2, $5, $3);
  2621.           cplus_decl_attributes ($$, $4, prefix_attributes); }
  2622.     | ':' expr_no_commas
  2623.         { $$ = grokbitfield (NULL_TREE, NULL_TREE, $2); }
  2624.     | error
  2625.         { $$ = NULL_TREE; }
  2626.  
  2627.     /* These rules introduce a reduce/reduce conflict; in
  2628.         typedef int foo, bar;
  2629.         class A {
  2630.           foo (bar);
  2631.         };
  2632.        should "A::foo" be declared as a function or "A::bar" as a data
  2633.        member? In other words, is "bar" an after_type_declarator or a
  2634.        parmlist? */
  2635.     | typed_declspecs '(' parmlist ')' type_quals exception_specification_opt maybeasm maybe_attribute maybe_init
  2636.         { $$ = build_parse_node (CALL_EXPR, TREE_VALUE ($1),
  2637.                      $3, $5);
  2638.           $$ = grokfield ($$, TREE_CHAIN ($1), $6, $9, $7);
  2639.           cplus_decl_attributes ($$, $8, prefix_attributes); }
  2640.     | typed_declspecs LEFT_RIGHT type_quals exception_specification_opt maybeasm maybe_attribute maybe_init
  2641.         { $$ = build_parse_node (CALL_EXPR, TREE_VALUE ($1),
  2642.                      empty_parms (), $3);
  2643.           $$ = grokfield ($$, TREE_CHAIN ($1), $4, $7, $5);
  2644.           cplus_decl_attributes ($$, $6, prefix_attributes); }
  2645.     | using_decl
  2646.         { $$ = do_class_using_decl ($1); }
  2647.     ;
  2648.  
  2649. /* The case of exactly one component is handled directly by component_decl. */
  2650. components:
  2651.       /* empty: possibly anonymous */
  2652.         { $$ = NULL_TREE; }
  2653.     | component_declarator0
  2654.     | components ',' component_declarator
  2655.         {
  2656.           /* In this context, void_type_node encodes
  2657.              friends.  They have been recorded elsewhere.  */
  2658.           if ($$ == void_type_node)
  2659.             $$ = $3;
  2660.           else
  2661.             $$ = chainon ($$, $3);
  2662.         }
  2663.     ;
  2664.  
  2665. notype_components:
  2666.       /* empty: possibly anonymous */
  2667.         { $$ = NULL_TREE; }
  2668.     | notype_component_declarator0
  2669.     | notype_components ',' notype_component_declarator
  2670.         {
  2671.           /* In this context, void_type_node encodes
  2672.              friends.  They have been recorded elsewhere.  */
  2673.           if ($$ == void_type_node)
  2674.             $$ = $3;
  2675.           else
  2676.             $$ = chainon ($$, $3);
  2677.         }
  2678.     ;
  2679.  
  2680. component_declarator0:
  2681.       after_type_component_declarator0
  2682.     | notype_component_declarator0
  2683.     ;
  2684.  
  2685. component_declarator:
  2686.       after_type_component_declarator
  2687.     | notype_component_declarator
  2688.     ;
  2689.  
  2690. after_type_component_declarator0:
  2691.       after_type_declarator exception_specification_opt maybeasm maybe_attribute maybe_init
  2692.         { current_declspecs = $<ttype>0;
  2693.           $$ = grokfield ($$, current_declspecs, $2, $5, $3);
  2694.           cplus_decl_attributes ($$, $4, prefix_attributes); }
  2695.     | TYPENAME ':' expr_no_commas maybe_attribute
  2696.         { current_declspecs = $<ttype>0;
  2697.           $$ = grokbitfield ($$, current_declspecs, $3);
  2698.           cplus_decl_attributes ($$, $4, prefix_attributes); }
  2699.     ;
  2700.  
  2701. notype_component_declarator0:
  2702.       notype_declarator exception_specification_opt maybeasm maybe_attribute maybe_init
  2703.         { current_declspecs = $<ttype>0;
  2704.           $$ = grokfield ($$, current_declspecs, $2, $5, $3);
  2705.           cplus_decl_attributes ($$, $4, prefix_attributes); }
  2706.     | IDENTIFIER ':' expr_no_commas maybe_attribute
  2707.         { current_declspecs = $<ttype>0;
  2708.           $$ = grokbitfield ($$, current_declspecs, $3);
  2709.           cplus_decl_attributes ($$, $4, prefix_attributes); }
  2710.     | ':' expr_no_commas maybe_attribute
  2711.         { current_declspecs = $<ttype>0;
  2712.           $$ = grokbitfield (NULL_TREE, current_declspecs, $2);
  2713.           cplus_decl_attributes ($$, $3, prefix_attributes); }
  2714.     ;
  2715.  
  2716. after_type_component_declarator:
  2717.       after_type_declarator exception_specification_opt maybeasm maybe_attribute maybe_init
  2718.         { $$ = grokfield ($$, current_declspecs, $2, $5, $3);
  2719.           cplus_decl_attributes ($$, $4, prefix_attributes); }
  2720.     | TYPENAME ':' expr_no_commas maybe_attribute
  2721.         { $$ = grokbitfield ($$, current_declspecs, $3);
  2722.           cplus_decl_attributes ($$, $4, prefix_attributes); }
  2723.     ;
  2724.  
  2725. notype_component_declarator:
  2726.       notype_declarator exception_specification_opt maybeasm maybe_attribute maybe_init
  2727.         { $$ = grokfield ($$, current_declspecs, $2, $5, $3);
  2728.           cplus_decl_attributes ($$, $4, prefix_attributes); }
  2729.     | IDENTIFIER ':' expr_no_commas maybe_attribute
  2730.         { $$ = grokbitfield ($$, current_declspecs, $3);
  2731.           cplus_decl_attributes ($$, $4, prefix_attributes); }
  2732.     | ':' expr_no_commas maybe_attribute
  2733.         { $$ = grokbitfield (NULL_TREE, current_declspecs, $2);
  2734.           cplus_decl_attributes ($$, $3, prefix_attributes); }
  2735.     ;
  2736.  
  2737. /* We chain the enumerators in reverse order.
  2738.    Because of the way enums are built, the order is
  2739.    insignificant.  Take advantage of this fact.  */
  2740.  
  2741. enumlist:
  2742.       enumerator
  2743.     | enumlist ',' enumerator
  2744.         { TREE_CHAIN ($3) = $$; $$ = $3; }
  2745.     ;
  2746.  
  2747. enumerator:
  2748.       identifier
  2749.         { $$ = build_enumerator ($$, NULL_TREE); }
  2750.     | identifier '=' expr_no_commas
  2751.         { $$ = build_enumerator ($$, $3); }
  2752.     ;
  2753.  
  2754. /* ANSI new-type-id (5.3.4) */
  2755. new_type_id:
  2756.       type_specifier_seq new_declarator
  2757.         { $$ = build_decl_list ($$, $2); }
  2758.     | type_specifier_seq %prec EMPTY
  2759.         { $$ = build_decl_list ($$, NULL_TREE); }
  2760.     /* GNU extension to allow arrays of arbitrary types with
  2761.        non-constant dimension.  */
  2762.     | '(' type_id ')' '[' expr ']'
  2763.         {
  2764.           if (pedantic)
  2765.             pedwarn ("ANSI C++ forbids array dimensions with parenthesized type in new");
  2766.           $$ = build_parse_node (ARRAY_REF, TREE_VALUE ($2), $5);
  2767.           $$ = build_decl_list (TREE_PURPOSE ($2), $$);
  2768.         }
  2769.     ;
  2770.  
  2771. type_quals:
  2772.       /* empty */ %prec EMPTY
  2773.         { $$ = NULL_TREE; }
  2774.     | type_quals TYPE_QUAL
  2775.         { $$ = decl_tree_cons (NULL_TREE, $2, $$); }
  2776.     ;
  2777.  
  2778. nonempty_type_quals:
  2779.       TYPE_QUAL
  2780.         { $$ = IDENTIFIER_AS_LIST ($$); }
  2781.     | nonempty_type_quals TYPE_QUAL
  2782.         { $$ = decl_tree_cons (NULL_TREE, $2, $$); }
  2783.     ;
  2784.  
  2785. /* These rules must follow the rules for function declarations
  2786.    and component declarations.  That way, longer rules are preferred.  */
  2787.  
  2788. suspend_mom:
  2789.     { $<itype>$ = suspend_momentary (); } 
  2790.  
  2791. /* An expression which will not live on the momentary obstack.  */
  2792. nonmomentary_expr:
  2793.     suspend_mom expr
  2794.     { resume_momentary ((int) $<itype>1); $$ = $2; }
  2795.     ;
  2796.  
  2797. /* An expression which will not live on the momentary obstack.  */
  2798. maybe_parmlist:
  2799.       suspend_mom '(' nonnull_exprlist ')'
  2800.         { resume_momentary ((int) $<itype>1); $$ = $3; }
  2801.     | suspend_mom '(' parmlist ')'
  2802.         { resume_momentary ((int) $<itype>1); $$ = $3; }
  2803.     | suspend_mom LEFT_RIGHT
  2804.         { resume_momentary ((int) $<itype>1); $$ = empty_parms (); }
  2805.     | suspend_mom '(' error ')'
  2806.         { resume_momentary ((int) $<itype>1); $$ = NULL_TREE; }
  2807.     ;
  2808.  
  2809. /* A declarator that is allowed only after an explicit typespec.  */
  2810. /* may all be followed by prec '.' */
  2811. after_type_declarator:
  2812.       '*' nonempty_type_quals after_type_declarator  %prec UNARY
  2813.         { $$ = make_pointer_declarator ($2, $3); }
  2814.     | '&' nonempty_type_quals after_type_declarator  %prec UNARY
  2815.         { $$ = make_reference_declarator ($2, $3); }
  2816.     | '*' after_type_declarator  %prec UNARY
  2817.         { $$ = make_pointer_declarator (NULL_TREE, $2); }
  2818.     | '&' after_type_declarator  %prec UNARY
  2819.         { $$ = make_reference_declarator (NULL_TREE, $2); }
  2820.     | ptr_to_mem type_quals after_type_declarator
  2821.         { tree arg = make_pointer_declarator ($2, $3);
  2822.           $$ = build_parse_node (SCOPE_REF, $1, arg);
  2823.         }
  2824.     | direct_after_type_declarator
  2825.     ;
  2826.  
  2827. qualified_type_name:
  2828.       type_name %prec EMPTY
  2829.         {
  2830.           /* Remember that this name has been used in the class
  2831.              definition, as per [class.scope0] */
  2832.           if (current_class_type
  2833.               && TYPE_BEING_DEFINED (current_class_type)
  2834.               && ! IDENTIFIER_CLASS_VALUE ($$))
  2835.             {
  2836.               tree t = lookup_name ($$, -2);
  2837.               if (t)
  2838.             pushdecl_class_level (t);
  2839.             }
  2840.         }
  2841.     | nested_type
  2842.     ;
  2843.  
  2844. nested_type:
  2845.     nested_name_specifier type_name %prec EMPTY
  2846.         { $$ = $2; }
  2847.     ;
  2848.  
  2849. direct_after_type_declarator:
  2850.       direct_after_type_declarator maybe_parmlist type_quals %prec '.'
  2851.         { $$ = build_parse_node (CALL_EXPR, $$, $2, $3); }
  2852.     | direct_after_type_declarator '[' nonmomentary_expr ']'
  2853.         { $$ = build_parse_node (ARRAY_REF, $$, $3); }
  2854.     | direct_after_type_declarator '[' ']'
  2855.         { $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); }
  2856.     | '(' after_type_declarator ')'
  2857.         { $$ = $2; }
  2858.     | nested_name_specifier type_name %prec EMPTY
  2859.         { push_nested_class (TREE_TYPE ($$), 3);
  2860.           $$ = build_parse_node (SCOPE_REF, $$, $2);
  2861.           TREE_COMPLEXITY ($$) = current_class_depth; }
  2862.     | type_name %prec EMPTY
  2863.     ;
  2864.  
  2865. /* A declarator allowed whether or not there has been
  2866.    an explicit typespec.  These cannot redeclare a typedef-name.  */
  2867.  
  2868. notype_declarator:
  2869.       '*' nonempty_type_quals notype_declarator  %prec UNARY
  2870.         { $$ = make_pointer_declarator ($2, $3); }
  2871.     | '&' nonempty_type_quals notype_declarator  %prec UNARY
  2872.         { $$ = make_reference_declarator ($2, $3); }
  2873.     | '*' notype_declarator  %prec UNARY
  2874.         { $$ = make_pointer_declarator (NULL_TREE, $2); }
  2875.     | '&' notype_declarator  %prec UNARY
  2876.         { $$ = make_reference_declarator (NULL_TREE, $2); }
  2877.     | ptr_to_mem type_quals notype_declarator
  2878.         { tree arg = make_pointer_declarator ($2, $3);
  2879.           $$ = build_parse_node (SCOPE_REF, $1, arg);
  2880.         }
  2881.     | direct_notype_declarator
  2882.     ;
  2883.  
  2884. complex_notype_declarator:
  2885.       '*' nonempty_type_quals notype_declarator  %prec UNARY
  2886.         { $$ = make_pointer_declarator ($2, $3); }
  2887.     | '&' nonempty_type_quals notype_declarator  %prec UNARY
  2888.         { $$ = make_reference_declarator ($2, $3); }
  2889.     | '*' complex_notype_declarator  %prec UNARY
  2890.         { $$ = make_pointer_declarator (NULL_TREE, $2); }
  2891.     | '&' complex_notype_declarator  %prec UNARY
  2892.         { $$ = make_reference_declarator (NULL_TREE, $2); }
  2893.     | ptr_to_mem type_quals notype_declarator
  2894.         { tree arg = make_pointer_declarator ($2, $3);
  2895.           $$ = build_parse_node (SCOPE_REF, $1, arg);
  2896.         }
  2897.     | complex_direct_notype_declarator
  2898.     ;
  2899.  
  2900. complex_direct_notype_declarator:
  2901.       direct_notype_declarator maybe_parmlist type_quals  %prec '.'
  2902.         { $$ = build_parse_node (CALL_EXPR, $$, $2, $3); }
  2903.     | '(' complex_notype_declarator ')'
  2904.         { $$ = $2; }
  2905.     | direct_notype_declarator '[' nonmomentary_expr ']'
  2906.         { $$ = build_parse_node (ARRAY_REF, $$, $3); }
  2907.     | direct_notype_declarator '[' ']'
  2908.         { $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); }
  2909.     | notype_qualified_id
  2910.         { push_nested_class (TREE_TYPE (OP0 ($$)), 3);
  2911.           TREE_COMPLEXITY ($$) = current_class_depth; }
  2912.     ;
  2913.  
  2914. qualified_id:
  2915.     nested_name_specifier unqualified_id
  2916.         { got_scope = NULL_TREE;
  2917.           $$ = build_parse_node (SCOPE_REF, $$, $2); }
  2918.     ;
  2919.  
  2920. notype_qualified_id:
  2921.     nested_name_specifier notype_unqualified_id
  2922.         { got_scope = NULL_TREE;
  2923.           $$ = build_parse_node (SCOPE_REF, $$, $2); }
  2924.     ;
  2925.  
  2926. overqualified_id:
  2927.       notype_qualified_id
  2928.     | global_scope notype_qualified_id
  2929.         { $$ = $2; }
  2930.     ;
  2931.  
  2932. functional_cast:
  2933.       typespec '(' nonnull_exprlist ')'
  2934.         { $$ = build_functional_cast ($$, $3); }
  2935.     | typespec '(' expr_or_declarator ')'
  2936.         { $$ = reparse_decl_as_expr ($$, $3); }
  2937.     | typespec fcast_or_absdcl %prec EMPTY
  2938.         { $$ = reparse_absdcl_as_expr ($$, $2); }
  2939.     ;
  2940.  
  2941. type_name:
  2942.       TYPENAME
  2943.     | template_type %prec EMPTY
  2944.     ;
  2945.  
  2946. nested_name_specifier:
  2947.       nested_name_specifier_1
  2948.     | nested_name_specifier nested_name_specifier_1
  2949.         { $$ = $2; }
  2950.     ;
  2951.  
  2952. /* Why the @#$%^& do type_name and notype_identifier need to be expanded
  2953.    inline here?!?  (jason) */
  2954. nested_name_specifier_1:
  2955.       TYPENAME SCOPE
  2956.         { got_scope = TREE_TYPE ($$); }
  2957.     | NSNAME SCOPE
  2958.         { got_scope = $$; }
  2959.     | template_type SCOPE
  2960.         { got_scope = TREE_TYPE ($$); }
  2961. /*     These break 'const i;'
  2962.     | IDENTIFIER SCOPE
  2963.         {
  2964.          failed_scope:
  2965.           cp_error ("`%D' is not an aggregate typedef", 
  2966.                 lastiddecl ? lastiddecl : $$);
  2967.           $$ = error_mark_node;
  2968.         }
  2969.     | PTYPENAME SCOPE
  2970.         { goto failed_scope; } */
  2971.     ;
  2972.  
  2973. complete_type_name:
  2974.       qualified_type_name
  2975.     | global_scope qualified_type_name
  2976.         { $$ = $2; }
  2977.     ;
  2978.  
  2979. complex_type_name:
  2980.       nested_type
  2981.     | global_scope qualified_type_name
  2982.         { $$ = $2; }
  2983.     ;
  2984.  
  2985. ptr_to_mem:
  2986.       nested_name_specifier '*'
  2987.         { got_scope = NULL_TREE; }
  2988.     | global_scope nested_name_specifier '*'
  2989.         { $$ = $2; got_scope = NULL_TREE; }
  2990.     ;
  2991.  
  2992. /* All uses of explicit global scope must go through this nonterminal so
  2993.    that got_scope will be set before yylex is called to get the next token. */
  2994. global_scope:
  2995.       SCOPE
  2996.         { got_scope = void_type_node; }
  2997.     ;
  2998.  
  2999. /* ANSI new-declarator (5.3.4) */
  3000. new_declarator:
  3001.       '*' type_quals new_declarator
  3002.         { $$ = make_pointer_declarator ($2, $3); }
  3003.     | '*' type_quals  %prec EMPTY
  3004.         { $$ = make_pointer_declarator ($2, NULL_TREE); }
  3005.     | '&' type_quals new_declarator %prec EMPTY
  3006.         { $$ = make_reference_declarator ($2, $3); }
  3007.     | '&' type_quals %prec EMPTY
  3008.         { $$ = make_reference_declarator ($2, NULL_TREE); }
  3009.     | ptr_to_mem type_quals %prec EMPTY
  3010.         { tree arg = make_pointer_declarator ($2, NULL_TREE);
  3011.           $$ = build_parse_node (SCOPE_REF, $1, arg);
  3012.         }
  3013.     | ptr_to_mem type_quals new_declarator
  3014.         { tree arg = make_pointer_declarator ($2, $3);
  3015.           $$ = build_parse_node (SCOPE_REF, $1, arg);
  3016.         }
  3017.     | direct_new_declarator %prec EMPTY
  3018.     ;
  3019.  
  3020. /* ANSI direct-new-declarator (5.3.4) */
  3021. direct_new_declarator:
  3022.       '[' expr ']'
  3023.         { $$ = build_parse_node (ARRAY_REF, NULL_TREE, $2); }
  3024.     | direct_new_declarator '[' nonmomentary_expr ']'
  3025.         { $$ = build_parse_node (ARRAY_REF, $$, $3); }
  3026.     ;
  3027.  
  3028. /* ANSI abstract-declarator (8.1) */
  3029. absdcl:
  3030.       '*' nonempty_type_quals absdcl
  3031.         { $$ = make_pointer_declarator ($2, $3); }
  3032.     | '*' absdcl
  3033.         { $$ = make_pointer_declarator (NULL_TREE, $2); }
  3034.     | '*' nonempty_type_quals  %prec EMPTY
  3035.         { $$ = make_pointer_declarator ($2, NULL_TREE); }
  3036.     | '*' %prec EMPTY
  3037.         { $$ = make_pointer_declarator (NULL_TREE, NULL_TREE); }
  3038.     | '&' nonempty_type_quals absdcl
  3039.         { $$ = make_reference_declarator ($2, $3); }
  3040.     | '&' absdcl
  3041.         { $$ = make_reference_declarator (NULL_TREE, $2); }
  3042.     | '&' nonempty_type_quals %prec EMPTY
  3043.         { $$ = make_reference_declarator ($2, NULL_TREE); }
  3044.     | '&' %prec EMPTY
  3045.         { $$ = make_reference_declarator (NULL_TREE, NULL_TREE); }
  3046.     | ptr_to_mem type_quals %prec EMPTY
  3047.         { tree arg = make_pointer_declarator ($2, NULL_TREE);
  3048.           $$ = build_parse_node (SCOPE_REF, $1, arg);
  3049.         }
  3050.     | ptr_to_mem type_quals absdcl
  3051.         { tree arg = make_pointer_declarator ($2, $3);
  3052.           $$ = build_parse_node (SCOPE_REF, $1, arg);
  3053.         }
  3054.     | direct_abstract_declarator %prec EMPTY
  3055.     ;
  3056.  
  3057. /* ANSI direct-abstract-declarator (8.1) */
  3058. direct_abstract_declarator:
  3059.       '(' absdcl ')'
  3060.         { $$ = $2; }
  3061.       /* `(typedef)1' is `int'.  */
  3062.     | PAREN_STAR_PAREN
  3063.     | direct_abstract_declarator '(' parmlist ')' type_quals  %prec '.'
  3064.         { $$ = build_parse_node (CALL_EXPR, $$, $3, $5); }
  3065.     | direct_abstract_declarator LEFT_RIGHT type_quals  %prec '.'
  3066.         { $$ = build_parse_node (CALL_EXPR, $$, empty_parms (), $3); }
  3067.     | direct_abstract_declarator '[' nonmomentary_expr ']'  %prec '.'
  3068.         { $$ = build_parse_node (ARRAY_REF, $$, $3); }
  3069.     | direct_abstract_declarator '[' ']'  %prec '.'
  3070.         { $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); }
  3071.     | '(' complex_parmlist ')' type_quals  %prec '.'
  3072.         { $$ = build_parse_node (CALL_EXPR, NULL_TREE, $2, $4); }
  3073.     | regcast_or_absdcl type_quals %prec '.'
  3074.         { TREE_OPERAND ($$, 2) = $2; }
  3075.     | fcast_or_absdcl type_quals %prec '.'
  3076.         { TREE_OPERAND ($$, 2) = $2; }
  3077.     | '[' nonmomentary_expr ']'  %prec '.'
  3078.         { $$ = build_parse_node (ARRAY_REF, NULL_TREE, $2); }
  3079.     | '[' ']'  %prec '.'
  3080.         { $$ = build_parse_node (ARRAY_REF, NULL_TREE, NULL_TREE); }
  3081.     ;
  3082.  
  3083. /* For C++, decls and stmts can be intermixed, so we don't need to
  3084.    have a special rule that won't start parsing the stmt section
  3085.    until we have a stmt that parses without errors.  */
  3086.  
  3087. stmts:
  3088.       stmt
  3089.     | errstmt
  3090.     | stmts stmt
  3091.     | stmts errstmt
  3092.     ;
  3093.  
  3094. errstmt:  error ';'
  3095.     ;
  3096.  
  3097. /* build the LET_STMT node before parsing its contents,
  3098.   so that any LET_STMTs within the context can have their display pointers
  3099.   set up to point at this one.  */
  3100.  
  3101. .pushlevel:  /* empty */
  3102.         { emit_line_note (input_filename, lineno);
  3103.           pushlevel (0);
  3104.           clear_last_expr ();
  3105.           push_momentary ();
  3106.           expand_start_bindings (0); }
  3107.     ;
  3108.  
  3109. .poplevel:   /* empty */
  3110.         { expand_end_bindings (getdecls (), kept_level_p (), 1);
  3111.           $$ = poplevel (kept_level_p (), 1, 0);
  3112.           pop_momentary (); }
  3113.     ;
  3114.  
  3115. /* Read zero or more forward-declarations for labels
  3116.    that nested functions can jump to.  */
  3117. maybe_label_decls:
  3118.       /* empty */
  3119.     | label_decls
  3120.         { if (pedantic)
  3121.             pedwarn ("ANSI C++ forbids label declarations"); }
  3122.     ;
  3123.  
  3124. label_decls:
  3125.       label_decl
  3126.     | label_decls label_decl
  3127.     ;
  3128.  
  3129. label_decl:
  3130.       LABEL identifiers_or_typenames ';'
  3131.         { tree link;
  3132.           for (link = $2; link; link = TREE_CHAIN (link))
  3133.             {
  3134.               tree label = shadow_label (TREE_VALUE (link));
  3135.               C_DECLARED_LABEL_FLAG (label) = 1;
  3136.               declare_nonlocal_label (label);
  3137.             }
  3138.         }
  3139.     ;
  3140.  
  3141. /* This is the body of a function definition.
  3142.    It causes syntax errors to ignore to the next openbrace.  */
  3143. compstmt_or_error:
  3144.       compstmt
  3145.         {}
  3146.     | error compstmt
  3147.     ;
  3148.  
  3149. compstmt: '{' .pushlevel compstmtend .poplevel
  3150.         { $$ = $4; }
  3151.     ;
  3152.  
  3153. simple_if:
  3154.       IF
  3155.         { cond_stmt_keyword = "if"; }
  3156.       .pushlevel paren_cond_or_null
  3157.         { emit_line_note (input_filename, lineno);
  3158.           expand_start_cond ($4, 0); }
  3159.       implicitly_scoped_stmt
  3160.     ;
  3161.  
  3162. implicitly_scoped_stmt:
  3163.       compstmt
  3164.         { finish_stmt (); }
  3165.     | .pushlevel simple_stmt .poplevel
  3166.         { $$ = $3; }
  3167.     ;
  3168.  
  3169. stmt:
  3170.       compstmt
  3171.         { finish_stmt (); }
  3172.     | simple_stmt
  3173.     ;
  3174.  
  3175. simple_stmt:
  3176.       decl
  3177.         { finish_stmt ();
  3178.           prefix_attributes = NULL_TREE; }
  3179.     | expr ';'
  3180.         {
  3181.           tree expr = $1;
  3182.           emit_line_note (input_filename, lineno);
  3183.           /* Do default conversion if safe and possibly important,
  3184.              in case within ({...}).  */
  3185.           if ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
  3186.                && lvalue_p (expr))
  3187.               || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE)
  3188.             expr = default_conversion (expr);
  3189.           cplus_expand_expr_stmt (expr);
  3190.           clear_momentary ();
  3191.           finish_stmt (); }
  3192.     | simple_if ELSE
  3193.         { expand_start_else (); }
  3194.       implicitly_scoped_stmt
  3195.         { expand_end_cond (); }
  3196.       .poplevel
  3197.         { finish_stmt (); }
  3198.     | simple_if %prec IF
  3199.         { expand_end_cond ();
  3200.           expand_end_bindings (getdecls (), kept_level_p (), 1);
  3201.           poplevel (kept_level_p (), 1, 0);
  3202.           pop_momentary ();
  3203.           finish_stmt (); }
  3204.     | WHILE
  3205.         { emit_nop ();
  3206.           emit_line_note (input_filename, lineno);
  3207.           expand_start_loop (1);
  3208.           cond_stmt_keyword = "while"; }
  3209.       .pushlevel paren_cond_or_null
  3210.         { expand_exit_loop_if_false (0, $4); }
  3211.       already_scoped_stmt .poplevel
  3212.         { expand_end_loop ();
  3213.           finish_stmt (); }
  3214.     | DO
  3215.         { emit_nop ();
  3216.           emit_line_note (input_filename, lineno);
  3217.           expand_start_loop_continue_elsewhere (1); }
  3218.       implicitly_scoped_stmt WHILE
  3219.         { expand_loop_continue_here ();
  3220.           cond_stmt_keyword = "do"; }
  3221.       paren_expr_or_null ';'
  3222.         { emit_line_note (input_filename, lineno);
  3223.           expand_exit_loop_if_false (0, $6);
  3224.           expand_end_loop ();
  3225.           clear_momentary ();
  3226.           finish_stmt (); }
  3227.     | FOR
  3228.         { emit_line_note (input_filename, lineno);
  3229.           if (flag_new_for_scope)
  3230.             {
  3231.               /* Conditionalize .pushlevel */
  3232.               pushlevel (0);
  3233.               clear_last_expr ();
  3234.               push_momentary ();
  3235.               expand_start_bindings (0);
  3236.             }
  3237.         }
  3238.       '(' for.init.statement
  3239.         { emit_nop ();
  3240.           emit_line_note (input_filename, lineno);
  3241.           expand_start_loop_continue_elsewhere (1); }
  3242.       .pushlevel xcond ';'
  3243.         { emit_line_note (input_filename, lineno);
  3244.           if ($7) expand_exit_loop_if_false (0, $7); }
  3245.       xexpr ')'
  3246.         /* Don't let the tree nodes for $10 be discarded
  3247.            by clear_momentary during the parsing of the next stmt.  */
  3248.         { push_momentary (); }
  3249.       already_scoped_stmt .poplevel
  3250.         { emit_line_note (input_filename, lineno);
  3251.           expand_loop_continue_here ();
  3252.           if ($10) cplus_expand_expr_stmt ($10);
  3253.           pop_momentary ();
  3254.           expand_end_loop ();
  3255.           if (flag_new_for_scope)
  3256.             {
  3257.               expand_end_bindings (getdecls (), kept_level_p (), 1);
  3258.               poplevel (kept_level_p (), 1, 0);
  3259.               pop_momentary ();
  3260.             }
  3261.           finish_stmt (); }
  3262.     | SWITCH .pushlevel '(' condition ')'
  3263.         { emit_line_note (input_filename, lineno);
  3264.           c_expand_start_case ($4);
  3265.           push_switch ();
  3266.           /* Don't let the tree nodes for $4 be discarded by
  3267.              clear_momentary during the parsing of the next stmt.  */
  3268.           push_momentary (); }
  3269.       implicitly_scoped_stmt
  3270.         { expand_end_case ($4);
  3271.           pop_momentary ();
  3272.           pop_switch (); }
  3273.       .poplevel
  3274.         { finish_stmt (); }
  3275.     | CASE expr_no_commas ':'
  3276.         { register tree value = check_cp_case_value ($2);
  3277.           register tree label
  3278.             = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  3279.  
  3280.           if (value != error_mark_node)
  3281.             {
  3282.               tree duplicate;
  3283.               int success = pushcase (value, convert_and_check,
  3284.                           label, &duplicate);
  3285.               if (success == 1)
  3286.             cp_error ("case label `%E' not within a switch statement", $2);
  3287.               else if (success == 2)
  3288.             {
  3289.               cp_error ("duplicate case value `%E'", $2);
  3290.               cp_error_at ("previously used here", duplicate);
  3291.             }
  3292.               else if (success == 3)
  3293.             warning ("case value out of range");
  3294.               else if (success == 5)
  3295.             cp_error ("case label `%E' within scope of cleanup or variable array", $2);
  3296.             }
  3297.           define_case_label (label);
  3298.         }
  3299.       stmt
  3300.     | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
  3301.         { register tree value1 = check_cp_case_value ($2);
  3302.           register tree value2 = check_cp_case_value ($4);
  3303.           register tree label
  3304.             = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  3305.  
  3306.           if (pedantic)
  3307.             pedwarn ("ANSI C++ forbids range expressions in switch statement");
  3308.           if (value1 != error_mark_node
  3309.               && value2 != error_mark_node)
  3310.             {
  3311.               tree duplicate;
  3312.               int success = pushcase_range (value1, value2,
  3313.                             convert_and_check, label,
  3314.                             &duplicate);
  3315.               if (success == 1)
  3316.             error ("case label not within a switch statement");
  3317.               else if (success == 2)
  3318.             {
  3319.               error ("duplicate (or overlapping) case value");
  3320.               error_with_decl (duplicate, "this is the first entry overlapping that value");
  3321.             }
  3322.               else if (success == 3)
  3323.             warning ("case value out of range");
  3324.               else if (success == 4)
  3325.             warning ("empty range specified");
  3326.               else if (success == 5)
  3327.             error ("case label within scope of cleanup or variable array");
  3328.             }
  3329.           define_case_label (label);
  3330.         }
  3331.       stmt
  3332.     | DEFAULT ':'
  3333.         {
  3334.           tree duplicate;
  3335.           register tree label
  3336.             = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  3337.           int success = pushcase (NULL_TREE, 0, label, &duplicate);
  3338.           if (success == 1)
  3339.             error ("default label not within a switch statement");
  3340.           else if (success == 2)
  3341.             {
  3342.               error ("multiple default labels in one switch");
  3343.               error_with_decl (duplicate, "this is the first default label");
  3344.             }
  3345.           define_case_label (NULL_TREE);
  3346.         }
  3347.       stmt
  3348.     | BREAK ';'
  3349.         { emit_line_note (input_filename, lineno);
  3350.           if ( ! expand_exit_something ())
  3351.             error ("break statement not within loop or switch"); }
  3352.     | CONTINUE ';'
  3353.         { emit_line_note (input_filename, lineno);
  3354.           if (! expand_continue_loop (0))
  3355.             error ("continue statement not within a loop"); }
  3356.     | RETURN ';'
  3357.         { emit_line_note (input_filename, lineno);
  3358.           c_expand_return (NULL_TREE); }
  3359.     | RETURN expr ';'
  3360.         { emit_line_note (input_filename, lineno);
  3361.           c_expand_return ($2);
  3362.           finish_stmt ();
  3363.         }
  3364.     | asm_keyword maybe_type_qual '(' string ')' ';'
  3365.         { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
  3366.           emit_line_note (input_filename, lineno);
  3367.           expand_asm ($4);
  3368.           finish_stmt ();
  3369.         }
  3370.     /* This is the case with just output operands.  */
  3371.     | asm_keyword maybe_type_qual '(' string ':' asm_operands ')' ';'
  3372.         { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
  3373.           emit_line_note (input_filename, lineno);
  3374.           c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
  3375.                      $2 == ridpointers[(int)RID_VOLATILE],
  3376.                      input_filename, lineno);
  3377.           finish_stmt ();
  3378.         }
  3379.     /* This is the case with input operands as well.  */
  3380.     | asm_keyword maybe_type_qual '(' string ':' asm_operands ':' asm_operands ')' ';'
  3381.         { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
  3382.           emit_line_note (input_filename, lineno);
  3383.           c_expand_asm_operands ($4, $6, $8, NULL_TREE,
  3384.                      $2 == ridpointers[(int)RID_VOLATILE],
  3385.                      input_filename, lineno);
  3386.           finish_stmt ();
  3387.         }
  3388.     /* This is the case with clobbered registers as well.  */
  3389.     | asm_keyword maybe_type_qual '(' string ':' asm_operands ':'
  3390.       asm_operands ':' asm_clobbers ')' ';'
  3391.         { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
  3392.           emit_line_note (input_filename, lineno);
  3393.           c_expand_asm_operands ($4, $6, $8, $10,
  3394.                      $2 == ridpointers[(int)RID_VOLATILE],
  3395.                      input_filename, lineno);
  3396.           finish_stmt ();
  3397.         }
  3398.     | GOTO '*' expr ';'
  3399.         { emit_line_note (input_filename, lineno);
  3400.           expand_computed_goto ($3); }
  3401.     | GOTO identifier ';'
  3402.         { tree decl;
  3403.           emit_line_note (input_filename, lineno);
  3404.           decl = lookup_label ($2);
  3405.           TREE_USED (decl) = 1;
  3406.           expand_goto (decl); }
  3407.     | label_colon stmt
  3408.         { finish_stmt (); }
  3409.     | label_colon '}'
  3410.         { error ("label must be followed by statement");
  3411.           yyungetc ('}', 0);
  3412.           finish_stmt (); }
  3413.     | ';'
  3414.         { finish_stmt (); }
  3415.     | try_block
  3416.     ;
  3417.  
  3418. try_block:
  3419.       TRY
  3420.         { expand_start_try_stmts (); }
  3421.       compstmt
  3422.         { expand_end_try_stmts ();
  3423.           expand_start_all_catch (); }
  3424.       handler_seq
  3425.         { expand_end_all_catch (); }
  3426.     ;
  3427.  
  3428. handler_seq:
  3429.       /* empty */
  3430.     | handler_seq CATCH .pushlevel handler_args compstmt
  3431.         { expand_end_catch_block (); }
  3432.       .poplevel
  3433.     ;
  3434.  
  3435. type_specifier_seq:
  3436.       typed_typespecs %prec EMPTY
  3437.     | nonempty_type_quals %prec EMPTY
  3438.     ;
  3439.  
  3440. handler_args:
  3441.       '(' ELLIPSIS ')'
  3442.         { expand_start_catch_block (NULL_TREE, NULL_TREE); }
  3443.     /* This doesn't allow reference parameters, the below does.
  3444.     | '(' type_specifier_seq absdcl ')'
  3445.         { expand_start_catch_block ($2, $3); }
  3446.     | '(' type_specifier_seq ')'
  3447.         { expand_start_catch_block ($2, NULL_TREE); }
  3448.     | '(' type_specifier_seq notype_declarator ')'
  3449.         { expand_start_catch_block ($2, $3); }
  3450.     | '(' typed_typespecs after_type_declarator ')'
  3451.         { expand_start_catch_block ($2, $3); }
  3452.     This allows reference parameters... */
  3453.     | '(' parm ')'
  3454.         { expand_start_catch_block (TREE_PURPOSE ($2),
  3455.                         TREE_VALUE ($2)); }
  3456.     ;
  3457.  
  3458. label_colon:
  3459.       IDENTIFIER ':'
  3460.         { tree label;
  3461.         do_label:
  3462.           label = define_label (input_filename, lineno, $1);
  3463.           if (label)
  3464.             expand_label (label);
  3465.         }
  3466.     | PTYPENAME ':'
  3467.         { goto do_label; }
  3468.     | TYPENAME ':'
  3469.         { goto do_label; }
  3470.     ;
  3471.  
  3472. for.init.statement:
  3473.       xexpr ';'
  3474.         { if ($1) cplus_expand_expr_stmt ($1); }
  3475.     | decl
  3476.     | '{' compstmtend
  3477.     ;
  3478.  
  3479. /* Either a type-qualifier or nothing.  First thing in an `asm' statement.  */
  3480.  
  3481. maybe_type_qual:
  3482.     /* empty */
  3483.         { emit_line_note (input_filename, lineno);
  3484.           $$ = NULL_TREE; }
  3485.     | TYPE_QUAL
  3486.         { emit_line_note (input_filename, lineno); }
  3487.     ;
  3488.  
  3489. xexpr:
  3490.     /* empty */
  3491.         { $$ = NULL_TREE; }
  3492.     | expr
  3493.     | error
  3494.         { $$ = NULL_TREE; }
  3495.     ;
  3496.  
  3497. /* These are the operands other than the first string and colon
  3498.    in  asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x))  */
  3499. asm_operands: /* empty */
  3500.         { $$ = NULL_TREE; }
  3501.     | nonnull_asm_operands
  3502.     ;
  3503.  
  3504. nonnull_asm_operands:
  3505.       asm_operand
  3506.     | nonnull_asm_operands ',' asm_operand
  3507.         { $$ = chainon ($$, $3); }
  3508.     ;
  3509.  
  3510. asm_operand:
  3511.       STRING '(' expr ')'
  3512.         { $$ = build_tree_list ($$, $3); }
  3513.     ;
  3514.  
  3515. asm_clobbers:
  3516.       STRING
  3517.         { $$ = tree_cons (NULL_TREE, $$, NULL_TREE); }
  3518.     | asm_clobbers ',' STRING
  3519.         { $$ = tree_cons (NULL_TREE, $3, $$); }
  3520.     ;
  3521.  
  3522. /* This is what appears inside the parens in a function declarator.
  3523.    Its value is represented in the format that grokdeclarator expects.
  3524.  
  3525.    In C++, declaring a function with no parameters
  3526.    means that that function takes *no* parameters.  */
  3527.  
  3528. parmlist:  /* empty */
  3529.         {
  3530.           if (strict_prototype)
  3531.             $$ = void_list_node;
  3532.           else
  3533.             $$ = NULL_TREE;
  3534.         }
  3535.     | complex_parmlist
  3536.     | type_id
  3537.         { $$ = tree_cons (NULL_TREE, $$, void_list_node);
  3538.           TREE_PARMLIST ($$) = 1; }
  3539.     ;
  3540.  
  3541. /* This nonterminal does not include the common sequence '(' type_id ')',
  3542.    as it is ambiguous and must be disambiguated elsewhere.  */
  3543. complex_parmlist:
  3544.       parms
  3545.         {
  3546.           $$ = chainon ($$, void_list_node);
  3547.           TREE_PARMLIST ($$) = 1;
  3548.         }
  3549.     | parms_comma ELLIPSIS
  3550.         {
  3551.           TREE_PARMLIST ($$) = 1;
  3552.         }
  3553.     /* C++ allows an ellipsis without a separating ',' */
  3554.     | parms ELLIPSIS
  3555.         {
  3556.           TREE_PARMLIST ($$) = 1;
  3557.         }
  3558.     | type_id ELLIPSIS
  3559.         {
  3560.           $$ = build_tree_list (NULL_TREE, $$); 
  3561.           TREE_PARMLIST ($$) = 1;
  3562.         }
  3563.     | ELLIPSIS
  3564.         {
  3565.           /* ARM $8.2.5 has this as a boxed-off comment.  */
  3566.           if (pedantic)
  3567.             warning ("use of `...' without a first argument is non-portable");
  3568.           $$ = NULL_TREE;
  3569.         }
  3570.     | TYPENAME_ELLIPSIS
  3571.         {
  3572.           TREE_PARMLIST ($$) = 1;
  3573.         }
  3574.     | parms TYPENAME_ELLIPSIS
  3575.         {
  3576.           TREE_PARMLIST ($$) = 1;
  3577.         }
  3578.     | type_id TYPENAME_ELLIPSIS
  3579.         {
  3580.           $$ = build_tree_list (NULL_TREE, $$);
  3581.           TREE_PARMLIST ($$) = 1;
  3582.         }
  3583.     | parms ':'
  3584.         {
  3585.           /* This helps us recover from really nasty
  3586.              parse errors, for example, a missing right
  3587.              parenthesis.  */
  3588.           yyerror ("possibly missing ')'");
  3589.           $$ = chainon ($$, void_list_node);
  3590.           TREE_PARMLIST ($$) = 1;
  3591.           yyungetc (':', 0);
  3592.           yychar = ')';
  3593.         }
  3594.     | type_id ':'
  3595.         {
  3596.           /* This helps us recover from really nasty
  3597.              parse errors, for example, a missing right
  3598.              parenthesis.  */
  3599.           yyerror ("possibly missing ')'");
  3600.           $$ = tree_cons (NULL_TREE, $$, void_list_node);
  3601.           TREE_PARMLIST ($$) = 1;
  3602.           yyungetc (':', 0);
  3603.           yychar = ')';
  3604.         }
  3605.     ;
  3606.  
  3607. /* A nonempty list of parameter declarations or type names.  */
  3608. parms:
  3609.       named_parm
  3610.         { $$ = build_tree_list (NULL_TREE, $$); }
  3611.     | parm '=' init
  3612.         { $$ = build_tree_list ($3, $$); }
  3613.     | parms_comma full_parm
  3614.         { $$ = chainon ($$, $2); }
  3615.     | parms_comma bad_parm
  3616.         { $$ = chainon ($$, build_tree_list (NULL_TREE, $2)); }
  3617.     | parms_comma bad_parm '=' init
  3618.         { $$ = chainon ($$, build_tree_list ($4, $2)); }
  3619.     ;
  3620.  
  3621. parms_comma:
  3622.       parms ','
  3623.     | type_id ','
  3624.         { $$ = build_tree_list (NULL_TREE, $$); }
  3625.     ;
  3626.  
  3627. /* A single parameter declaration or parameter type name,
  3628.    as found in a parmlist.  The first four cases make up for 10%
  3629.    of the time spent parsing C++.  We cannot use them because
  3630.    of `int id[]' which won't get parsed properly.  */
  3631. named_parm:
  3632. /*
  3633.       typed_declspecs dont_see_typename '*' IDENTIFIER
  3634.         { $$ = build_tree_list ($$, build_parse_node (INDIRECT_REF, $4));
  3635.           see_typename (); }
  3636.     | typed_declspecs dont_see_typename '&' IDENTIFIER
  3637.         { $$ = build_tree_list ($$, build_parse_node (ADDR_EXPR, $4));
  3638.           see_typename (); }
  3639.     | TYPENAME IDENTIFIER
  3640.         { $$ = build_tree_list (get_decl_list ($$), $2);  }
  3641.     | TYPESPEC IDENTIFIER
  3642.         { $$ = build_tree_list (get_decl_list ($$), $2); }
  3643.     | */
  3644.     /* Here we expand typed_declspecs inline to avoid mis-parsing of
  3645.        TYPESPEC IDENTIFIER.  */
  3646.       typed_declspecs1 declarator
  3647.         { $$ = build_tree_list ($$, $2); }
  3648.     | typed_typespecs declarator
  3649.         { $$ = build_tree_list ($$, $2); }
  3650.     | typespec declarator
  3651.         { $$ = build_tree_list (get_decl_list ($$), $2); }
  3652.     | typed_declspecs1 absdcl
  3653.         { $$ = build_tree_list ($$, $2); }
  3654.     | typed_declspecs1 %prec EMPTY
  3655.         { $$ = build_tree_list ($$, NULL_TREE); }
  3656.     | declmods notype_declarator
  3657.         { $$ = build_tree_list ($$, $2); }
  3658.     ;
  3659.  
  3660. full_parm:
  3661.       parm maybe_init
  3662.         { $$ = build_tree_list ($2, $$); }
  3663.     ;
  3664.  
  3665. parm:
  3666.     named_parm
  3667.     | type_id
  3668.     ;
  3669.  
  3670. see_typename: %prec EMPTY
  3671.     { see_typename (); }
  3672.     ;
  3673.  
  3674. /* 
  3675. dont_see_typename: %prec EMPTY
  3676.     { dont_see_typename (); }
  3677.     ; 
  3678.  
  3679. try_for_typename:
  3680.         {
  3681.       if ($<ttype>-1 == error_mark_node)
  3682.             $$ = 0;
  3683.           else
  3684.             {
  3685.               $$ = 1;
  3686.               pushclass ($<ttype>-1, 1);
  3687.             }
  3688.         }
  3689.     ;
  3690. */
  3691.  
  3692. bad_parm:
  3693.       /* empty */ %prec EMPTY
  3694.         {
  3695.           error ("type specifier omitted for parameter");
  3696.           $$ = build_tree_list (integer_type_node, NULL_TREE);
  3697.         }
  3698.     | notype_declarator
  3699.         {
  3700.           error ("type specifier omitted for parameter");
  3701.           $$ = build_tree_list (integer_type_node, $$);
  3702.         }
  3703.     ;
  3704.  
  3705. exception_specification_opt:
  3706.       %prec EMPTY /* empty */
  3707.         { $$ = NULL_TREE; }
  3708.     | THROW '(' ansi_raise_identifiers  ')' %prec EMPTY
  3709.         { $$ = $3; }
  3710.     | THROW LEFT_RIGHT %prec EMPTY
  3711.         { $$ = build_decl_list (NULL_TREE, NULL_TREE); }
  3712.     ;
  3713.  
  3714. ansi_raise_identifier:
  3715.       type_id
  3716.         { $$ = build_decl_list (NULL_TREE, groktypename($$)); }
  3717.     ;
  3718.  
  3719. ansi_raise_identifiers:
  3720.       ansi_raise_identifier
  3721.     | ansi_raise_identifiers ',' ansi_raise_identifier
  3722.         {
  3723.           TREE_CHAIN ($3) = $$;
  3724.           $$ = $3;
  3725.         }
  3726.     ;
  3727.  
  3728. conversion_declarator:
  3729.       /* empty */ %prec EMPTY
  3730.         { $$ = NULL_TREE; }
  3731.     | '*' type_quals conversion_declarator
  3732.         { $$ = make_pointer_declarator ($2, $3); }
  3733.     | '&' type_quals conversion_declarator
  3734.         { $$ = make_reference_declarator ($2, $3); }
  3735.     | ptr_to_mem type_quals conversion_declarator
  3736.         { tree arg = make_pointer_declarator ($2, $3);
  3737.           $$ = build_parse_node (SCOPE_REF, $1, arg);
  3738.         }
  3739.     ;
  3740.  
  3741. operator: OPERATOR
  3742.         { got_scope = NULL_TREE; }
  3743.     ;
  3744.  
  3745. operator_name:
  3746.       operator '*'
  3747.         { $$ = ansi_opname[MULT_EXPR]; }
  3748.     | operator '/'
  3749.         { $$ = ansi_opname[TRUNC_DIV_EXPR]; }
  3750.     | operator '%'
  3751.         { $$ = ansi_opname[TRUNC_MOD_EXPR]; }
  3752.     | operator '+'
  3753.         { $$ = ansi_opname[PLUS_EXPR]; }
  3754.     | operator '-'
  3755.         { $$ = ansi_opname[MINUS_EXPR]; }
  3756.     | operator '&'
  3757.         { $$ = ansi_opname[BIT_AND_EXPR]; }
  3758.     | operator '|'
  3759.         { $$ = ansi_opname[BIT_IOR_EXPR]; }
  3760.     | operator '^'
  3761.         { $$ = ansi_opname[BIT_XOR_EXPR]; }
  3762.     | operator '~'
  3763.         { $$ = ansi_opname[BIT_NOT_EXPR]; }
  3764.     | operator ','
  3765.         { $$ = ansi_opname[COMPOUND_EXPR]; }
  3766.     | operator ARITHCOMPARE
  3767.         { $$ = ansi_opname[$2]; }
  3768.     | operator '<'
  3769.         { $$ = ansi_opname[LT_EXPR]; }
  3770.     | operator '>'
  3771.         { $$ = ansi_opname[GT_EXPR]; }
  3772.     | operator EQCOMPARE
  3773.         { $$ = ansi_opname[$2]; }
  3774.     | operator ASSIGN
  3775.         { $$ = ansi_assopname[$2]; }
  3776.     | operator '='
  3777.         { $$ = ansi_opname [MODIFY_EXPR]; }
  3778.     | operator LSHIFT
  3779.         { $$ = ansi_opname[$2]; }
  3780.     | operator RSHIFT
  3781.         { $$ = ansi_opname[$2]; }
  3782.     | operator PLUSPLUS
  3783.         { $$ = ansi_opname[POSTINCREMENT_EXPR]; }
  3784.     | operator MINUSMINUS
  3785.         { $$ = ansi_opname[PREDECREMENT_EXPR]; }
  3786.     | operator ANDAND
  3787.         { $$ = ansi_opname[TRUTH_ANDIF_EXPR]; }
  3788.     | operator OROR
  3789.         { $$ = ansi_opname[TRUTH_ORIF_EXPR]; }
  3790.     | operator '!'
  3791.         { $$ = ansi_opname[TRUTH_NOT_EXPR]; }
  3792.     | operator '?' ':'
  3793.         { $$ = ansi_opname[COND_EXPR]; }
  3794.     | operator MIN_MAX
  3795.         { $$ = ansi_opname[$2]; }
  3796.     | operator POINTSAT  %prec EMPTY
  3797.         { $$ = ansi_opname[COMPONENT_REF]; }
  3798.     | operator POINTSAT_STAR  %prec EMPTY
  3799.         { $$ = ansi_opname[MEMBER_REF]; }
  3800.     | operator LEFT_RIGHT
  3801.         { $$ = ansi_opname[CALL_EXPR]; }
  3802.     | operator '[' ']'
  3803.         { $$ = ansi_opname[ARRAY_REF]; }
  3804.     | operator NEW %prec EMPTY
  3805.         { $$ = ansi_opname[NEW_EXPR]; }
  3806.     | operator DELETE %prec EMPTY
  3807.         { $$ = ansi_opname[DELETE_EXPR]; }
  3808.     | operator NEW '[' ']'
  3809.         { $$ = ansi_opname[VEC_NEW_EXPR]; }
  3810.     | operator DELETE '[' ']'
  3811.         { $$ = ansi_opname[VEC_DELETE_EXPR]; }
  3812.     /* Names here should be looked up in class scope ALSO.  */
  3813.     | operator type_specifier_seq conversion_declarator
  3814.         { $$ = grokoptypename ($2, $3); }
  3815.     | operator error
  3816.         { $$ = ansi_opname[ERROR_MARK]; }
  3817.     ;
  3818.  
  3819. %%
  3820.  
  3821. #ifdef SPEW_DEBUG
  3822. const char *
  3823. debug_yytranslate (value)
  3824.     int value;
  3825. {
  3826.   return yytname[YYTRANSLATE (value)];
  3827. }
  3828.  
  3829. #endif
  3830.